Maximum Rest
InterviewTime limit2sMemory limit1024 MB
Choose workdays, each capped at W_i, so total work reaches M while the smallest gap between chosen workdays is as large as possible.
- Level
Medium6 of 10
- Topics
- Binary search, Dynamic programming, Sliding window
- Solved
- No attempts yet
Problem
Amel is known as the most capable employee at the SKH company. However, Amel has very poor stamina and tires quickly after a day of work, so Amel wants to rest for as long as possible after each stretch of work. On day , Amel can work at most , and Amel must complete a total of units of work. Amel wants to maximize the minimum length of the consecutive rest periods between working days.
For example, suppose the workloads for 7 days are and the quota is . If Amel works on days 1, 3, and 7, then fills the quota. The rest periods are 1 day and 3 days, so the minimum is 1 day. If Amel works on days 2 and 6, then fills the quota, and the rest period is 3 days, so the minimum is 3 days. If Amel works on days 6 and 7, the gap between working days is 0 days, so the minimum is 0.
Rest before the first workday or after the last workday is not counted as a rest period.
Input
The first line contains the number of days () and the quota (), separated by a space.
The second line contains (, ), the maximum amount of work Amel can do on day , separated by spaces.
All input values are integers.
Output
Print the maximum possible value of the minimum length of consecutive rest periods.
If Amel cannot fill the quota even by working all days, print -1. If the quota can be filled in one day, print "Free!" (without the quotes).