AIOC Banner

Problem: Heatwave

Want to try solving this problem? You can submit your code online if you log in or register.


Heatwave

Input File: heatin.txt
Output File: heatout.txt
Time Limit: 1 second

Summer is fast approaching. There are people who love the sun, thrive in the warmth and enjoy lazing by the water. Then there are people who are irritated by the flies, the sand and of course the hot days. Different countries and cities tend to have different definitions of what is considered a "hot" day. For example, in Australia a hot day might be considered anything from 36 degrees up. However, in Iceland a day of 20 degrees or more is highly unusual and could send the locals into heat stress.

A "heatwave" is defined to be a series of one or more consecutive hot days. In hope of finding a nice warm city to retire, you wish to determine for a given city how many days the longest heatwave lasted. Your sources have obtained all the historical temperature data for the cities you are interested in, together with the lowest temperature that constitutes a heatwave for the city.

Your task is to write a program that can determine the longest observed heatwave.

For example, consider the following historical data for Perth. People in Perth call a day hot when the temperature hits 38 degrees or more. The hot days are underlined below:

31   39   42   33   30   33   40   38   39   41   37   34   27

Here, the longest heatwave lasted four days (the consecutive days where the temperature hit 40, 38, 39 and 41).

Constraints

To evaluate your solution, the judges will run your program against several different input files. All of these files will adhere to the following bounds:

As some of the test cases will be quite large, you may need to think about how well your solution scales for larger input values. However, not all the cases will be large. Specifically:

Input

Your program should read from the file heatin.txt. The first line of this file will contain two space-separated integers N and H, as described above. Following this will be N lines each containing a single integer Ti, representing the maximum temperature on each day of the measurement period.

Output

Your program should write to the file heatout.txt. Your output file should consist of a single integer, specifying the length of the longest heatwave.

Sample Input 1

13 38 
31
39
42
33
30
33
40
38
39
41
37
34
27

Sample Output 1

4

Sample Input 2

5 40
28
39
38
27
34

Sample Output 2

0

Scoring

The score for each input scenario will be 100% if the correct answer is written to the output file, and 0% otherwise.

Note that in the AIO, some test cases were placed in batches. This means that that you needed to score full marks on all cases within a batch in order to get the marks for that batch. The training site version does not enforce this, and so unless your final score is 100, it may differ from the official one.

 


Privacy statement
© Australian Mathematics Trust 2001-2019

Contact: training@orac.amt.edu.au
Page generated: 24 May 2019,  4:16am AEST