T-Shirt Delivery
InterviewTime limit2sMemory limit512 MB
Given travel times and each recipient's earliest availability, simulate Bill's deliveries where he waits at most k minutes per stop and each handover takes t minutes, and report when he finishes.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation, Math, Greedy
- Solved
- No attempts yet
Problem
The New Zealand Algorithm Internet Team Olympiad (KINZA) has ended. After the olympiad the organizers decided to send T-shirts to every prize winner. Delivery of the T-shirts was assigned to the company where the courier Bill works.
Bill has to deliver T-shirts. He must deliver the parcels in the order in which they appear on his route sheet. If a parcel cannot be delivered, a refusal is marked on the route sheet and Bill drives to the next address.
Bill starts his workday at the company office at time 0. When he arrives at the address of a parcel's recipient, he waits at most minutes, and if the recipient opens the door within that time, Bill hands over the parcel; the handover itself, not counting the waiting time, takes minutes. If the door does not open within minutes and the recipient does not appear, Bill drives on. If the recipient appears exactly minutes after Bill's arrival, Bill notices it and the parcel is delivered. Bill's workday ends when he finishes handing over the last parcel or marks a refusal to accept it on the route sheet.
Bill's boss John wants to check how diligently Bill works. John knows how long it takes Bill to drive from the office to the first recipient and how long it takes to drive from one recipient to the next. He also conducted a phone survey and knows the time from which each T-shirt recipient will be at home. Now John wants to know when Bill will finish his workday.
Input
The first line of the input file contains three integers , , (, ).
The second line contains natural numbers , where is the time Bill needs to drive from the office to the first recipient, and is the time Bill needs to travel from the -th recipient to the -th. All do not exceed .
The third line contains non-negative integers (), where is the time from which the -th recipient is ready to accept the parcel. Bill starts at time 0.
Output
Print a single number: the minimum time in which Bill can complete his task.
Hint
In the example Bill arrives at the first recipient at time 1 and hands over the parcel immediately. At time 2 he leaves the first recipient and at time 7 he arrives at the second. He waits 3 minutes, until time 10, but the recipient does not appear, so Bill heads to the third recipient and arrives at time 14. That recipient is at home and accepts the parcel. Bill is therefore free at time 15.