Raehwan's Mission to Get a Girlfriend
InterviewTime limit1sMemory limit1024 MB
Given daily weight losses A_i, find the latest start day s such that dieting every day from s through N loses at least M units, or -1 if no start day works.
- Level
Easy3 of 10
- Topics
- Prefix sum, Two pointers
- Solved
- No attempts yet
Problem
Raehwan has a blind date days from now, and he wants to find a girlfriend. He decides to lose units of weight through a diet. Raehwan knows in advance the weight loss from dieting on day (). Because he keeps a regular routine, his weight does not change on days when he does not diet.
Find the latest day on which he can start his diet and still reach his goal before the blind date.
Input
The first line contains two integers () and (), separated by a space.
The second line contains integers , separated by spaces. ()
Output
Print the day number from which Raehwan should start his diet so that he postpones it as long as possible and still reaches his goal. If the diet can never succeed, print instead.