/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 233 点
問題文
高橋君は夏休みの自由研究として、地元の気象データを調べています。ある期間の N 日間について、毎日の最高気温(℃)が整数値で記録されています。
1 日目、2 日目、…、N 日目の最高気温はそれぞれ A_1, A_2, \ldots, A_N ℃ です。最高気温が K ℃ 以上の日を「暑い日」と呼ぶことにします。
高橋君は、連続して「暑い日」が何日続いたかに注目しています。具体的には、ある日からある日まで連続する 1 日以上の日の列であって、その中のすべての日が「暑い日」であるものを考えます。そのような日の列に含まれる日数の最大値を求めてください。「暑い日」が一日もない場合は 0 を出力してください。
制約
- 1 \leq N \leq 10^6
- -50 \leq K \leq 50
- -50 \leq A_i \leq 50 (1 \leq i \leq N)
- 入力はすべて整数である
入力
N K A_1 A_2 \ldots A_N
- 1 行目には、日数を表す整数 N と、「暑い日」の基準気温を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、各日の最高気温を表す N 個の整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
すべての日が「暑い日」であるような連続する日の列の日数の最大値を 1 行で出力せよ。「暑い日」が一日もない場合は 0 を出力せよ。
入力例 1
10 35 32 36 37 35 33 35 36 37 38 34
出力例 1
4
入力例 2
15 30 28 30 31 32 29 27 30 30 30 30 30 28 33 34 29
出力例 2
5
入力例 3
20 0 -5 -3 0 1 2 3 -1 -2 0 0 0 0 0 -4 1 2 3 4 5 -1
出力例 3
5
Score : 233 pts
Problem Statement
Takahashi is investigating local weather data as part of his summer vacation independent research project. For a period of N days, the daily maximum temperature (°C) has been recorded as an integer value.
The maximum temperatures on day 1, day 2, …, day N are A_1, A_2, \ldots, A_N °C, respectively. A day whose maximum temperature is K °C or higher is called a "hot day."
Takahashi is interested in how many consecutive "hot days" occurred in a row. Specifically, consider a sequence of one or more consecutive days from some day to some day such that every day in the sequence is a "hot day." Find the maximum number of days contained in such a sequence. If there are no "hot days" at all, output 0.
Constraints
- 1 \leq N \leq 10^6
- -50 \leq K \leq 50
- -50 \leq A_i \leq 50 (1 \leq i \leq N)
- All input values are integers
Input
N K A_1 A_2 \ldots A_N
- The first line contains an integer N representing the number of days and an integer K representing the threshold temperature for a "hot day," separated by a space.
- The second line contains N integers A_1, A_2, \ldots, A_N representing the maximum temperature on each day, separated by spaces.
Output
Output in one line the maximum number of days in a sequence of consecutive days where every day is a "hot day." If there are no "hot days" at all, output 0.
Sample Input 1
10 35 32 36 37 35 33 35 36 37 38 34
Sample Output 1
4
Sample Input 2
15 30 28 30 31 32 29 27 30 30 30 30 30 28 33 34 29
Sample Output 2
5
Sample Input 3
20 0 -5 -3 0 1 2 3 -1 -2 0 0 0 0 0 -4 1 2 3 4 5 -1
Sample Output 3
5