Float Lanterns
Time limit1sMemory limit1024 MB
Pick S consecutive lanterns and count pairs where a later-released lantern rises faster than an earlier one; output the maximum count over all windows.
- Level
Hard8 of 10
- Topics
- Sliding window, Divide and conquer, Array
- Solved
- No attempts yet
Problem
Geonguseu prepared lanterns that rise without limit into the sky to close out the festival. The lanterns are numbered to from left to right, and lantern rises by every second. At the start, all lanterns are placed at height . When the festival ends, Geonguseu will pick consecutive lanterns and release them one second apart, in order of increasing number.
When one lantern overtakes other lanterns, people make one wish for each lantern it overtakes. Geonguseu wants to choose the lanterns to release so that people make as many wishes as possible. Among all ways to pick consecutive lanterns, what is the maximum number of wishes people can make?
Input
The first line contains the number of lanterns and the number of lanterns to release , separated by a space.
The second line contains integers , separated by spaces, where is how much lantern rises each second.
Output
Print the number of wishes people make when Geonguseu chooses the lanterns to release so that this number is as large as possible.