#USACOC1111A. Above the Median
Above the Median
Farmer John has lined up his cows in a row to measure their heights; cow has height nanometers--FJ believes in precise measurements! He wants to take a picture of some contiguous subsequence of the cows to submit to a bovine photography contest at the county fair.
The fair has a very strange rule about all submitted photos: a photograph is only valid to submit if it depicts a group of cows whose median height is at least a certain threshold .
For purposes of this problem, we define the median of an array to be after is sorted, where gives rounded up to the nearest integer (or itself, it is an integer to begin with). For example the median of is , and the median of is .
Please help FJ count the number of different contiguous subsequences of hiscows that he could potentially submit to the photography contest.
Input Format
- Line : Two space-separated integers: and .
- Lines : Line contains the single integer .
Output Format:
- Line : The number of subsequences of FJ's cows that have median at least . Note this may not fit into a 32-bit integer.
4 6
10
5
6
2
7
Sample Details
Input Details:
FJ's four cows have heights , , , . We want to know how many contiguous subsequences have median at least .
Output Details:
There are possible contiguous subsequences to consider. Of these, only have median at least . They are , , , , , , .