Traffic Jam
InterviewTime limit2sMemory limit1024 MB
Given cars with start delays a_i and a repeating green-red light, find the time the last car passes the light.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Statement
A one-way road has a traffic light. There are cars waiting on the road, and each driver wants to pass as quickly as possible. Drivers never run a red light, so they must wait for green.
The light has only red and green. Green stays on for seconds, then red for seconds, then green again for seconds, and so on. At the first moment the light is green. A car may pass at the moment the light switches.
It is 7 a.m., and the drivers are sleepy. The -th driver needs seconds to realize that the light is green. The first car in line can start seconds after green begins. Each other car can start seconds after the car in front of it starts moving. Cars move fast, so the time to reach the light and pass through it is ignored. No car passes on red.
Find the time, counted from the first green, at which the last car passes the light.
Input
The first line contains integers (), , and (): the number of cars, the green duration, and the red duration, in seconds. The second line contains integers (): the seconds each driver needs to realize the light is green.
Output
Print one integer: the time at which the last car passes the light.