A - Fruit Sorting Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 233

問題文

高橋君は果物農家で、今日の収穫で N 個の果物を得ました。各果物 i の糖度を測定したところ、 S_i でした。

出荷の基準として、糖度が K 以上の果物のみを出荷することができます。糖度が K 未満の果物は規格外として出荷できません。

高橋君は、出荷できる果物(糖度が K 以上の果物)の糖度の平均値を知りたいと考えています。ただし、出荷できる果物が 1 つもない場合は、平均値を計算することができません。

出荷できる果物が 1 つ以上ある場合は、それらの糖度の平均値を出力してください。出荷できる果物が 1 つもない場合は -1 を出力してください。

制約

  • 1 \leq N \leq 10^6
  • 1 \leq K \leq 10^9
  • 1 \leq S_i \leq 10^9
  • 入力はすべて整数である。

入力

N K
S_1 S_2 \ldots S_N
  • 1 行目には、果物の個数を表す N 、出荷基準の糖度を表す K が、スペース区切りで与えられる。
  • 2 行目には、各果物の糖度を表す S_1, S_2, \ldots, S_N が、スペース区切りで与えられる。

出力

出荷できる果物(糖度が K 以上の果物)が 1 つ以上ある場合は、それらの糖度の平均値を出力せよ。出荷できる果物が 1 つもない場合は -1 を出力せよ。

なお、平均値を出力する場合、真の値との絶対誤差または相対誤差が 10^{-6} 以下であれば正解とする。


入力例 1

5 8
3 10 7 12 9

出力例 1

10.333333333333334

入力例 2

4 15
3 7 10 14

出力例 2

-1

入力例 3

10 50
45 60 55 30 70 48 52 49 80 51

出力例 3

61.333333333333336

入力例 4

20 500
120 600 450 800 300 550 499 501 750 200 630 480 520 999 100 500 350 680 490 510

出力例 4

640.0

入力例 5

1 1000000000
1000000000

出力例 5

1000000000.0

Score : 233 pts

Problem Statement

Takahashi is a fruit farmer and obtained N fruits from today's harvest. He measured the sugar content of each fruit i and found it to be S_i.

As a shipping criterion, only fruits with sugar content of K or higher can be shipped. Fruits with sugar content less than K are considered substandard and cannot be shipped.

Takahashi wants to know the average sugar content of the fruits that can be shipped (fruits with sugar content of K or higher). However, if there are no fruits that can be shipped, the average cannot be calculated.

If there is at least one fruit that can be shipped, output the average sugar content of those fruits. If there are no fruits that can be shipped, output -1.

Constraints

  • 1 \leq N \leq 10^6
  • 1 \leq K \leq 10^9
  • 1 \leq S_i \leq 10^9
  • All input values are integers.

Input

N K
S_1 S_2 \ldots S_N
  • The first line contains N, the number of fruits, and K, the minimum sugar content for shipping, separated by a space.
  • The second line contains S_1, S_2, \ldots, S_N, the sugar content of each fruit, separated by spaces.

Output

If there is at least one fruit that can be shipped (fruits with sugar content of K or higher), output the average sugar content of those fruits. If there are no fruits that can be shipped, output -1.

When outputting the average, the answer will be considered correct if the absolute error or relative error from the true value is at most 10^{-6}.


Sample Input 1

5 8
3 10 7 12 9

Sample Output 1

10.333333333333334

Sample Input 2

4 15
3 7 10 14

Sample Output 2

-1

Sample Input 3

10 50
45 60 55 30 70 48 52 49 80 51

Sample Output 3

61.333333333333336

Sample Input 4

20 500
120 600 450 800 300 550 499 501 750 200 630 480 520 999 100 500 350 680 490 510

Sample Output 4

640.0

Sample Input 5

1 1000000000
1000000000

Sample Output 5

1000000000.0