Military Enlistment
InterviewTime limit1sMemory limit1024 MB
Given daily volunteer points and a blood donation that blocks the next D days, find the fewest donations needed to reach at least M points, or -1 if impossible.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Prefix sum, Greedy
- Solved
- No attempts yet
Problem
Jinjin, who has reached the age of military service, wants to apply for the Republic of Korea Air Force recruit program. To be accepted, he needs bonus points, and because the Air Force has become more popular recently, he must collect at least points through volunteer work or blood donation.
There are days left until the application deadline. On day , he can take part in volunteer work that gives bonus points. He can donate blood on any day from to , and each donation gives him bonus points. However, after a donation, he cannot donate blood or do volunteer work for days, counting the donation day itself, so that he can rest enough.
Jinjin dislikes blood donation, so he wants to collect at least bonus points while donating as few times as possible. Find the minimum number of blood donations needed to collect at least bonus points by the application deadline.
Input
The first line contains two integers and , separated by a space, where is the number of days left until the deadline and is the bonus points needed to pass. (, )
The second line contains integers , separated by spaces, where is the bonus points from volunteer work on day . ()
The third line contains two integers and , separated by a space, where is the bonus points from one blood donation and is the number of days of rest needed after a donation. (, )
Output
Print the minimum number of blood donations needed to collect at least bonus points.
If it is impossible to collect at least bonus points, print -1.