Autobahn
Time limit1sMemory limit512 MB
Each driver stays for a time interval and owes extra fees for minutes when at least K drivers are present; choose X consecutive minutes to waive fees and maximize the waived total.
- Level
Hard8 of 10
- Topics
- Prefix sum, Sliding window, Sorting, Implementation
- Solved
- No attempts yet
Problem
There are people testing their racing cars on the notorious autobahn, where limits do not exist. In this task, however, limits do exist. So we kindly ask you to restrain yourself from submitting exponential complexity solutions.
Person came to the autobahn at the beginning of minute , paid for minutes of stay, and left at the end of minute . Unfortunately some stayed for longer than they paid for. The administration of the autobahn decided not to be very harsh and charge them only for those extra minutes in which there were at least people on the autobahn.
In a rush of generosity, the administration decided to introduce a happy hour, that is, an interval of continuous minutes for which they will not be paying extra charges. They picked the happy hour so that the sum of extra charges that will not be paid is maximal possible. Determine that sum.
Input
The first line contains the integers , , and from the task description ().
The next lines contain the integers , , and from the task description ().
Output
Print the required sum in a single line.
Hint
First sample explanation: The happy hour will span from the 4th minute until the 7th minute. Inside that interval, the first person should have paid extra for the 4th minute, and the second, third, and fourth person should have paid for the 6th and 7th minute.