Mansion and Deliveries
InterviewTime limit10sMemory limit512 MB
Deliveries arrive at sorted times; each round trip to the door costs 2M, so pick a subset of deliveries to answer while maximizing time spent in the study up to T.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Greedy, Sorting, Implementation
- Solved
- No attempts yet
Problem
Taro lives alone in a mansion. Taro likes studying, and today he plans to study in the study inside the mansion. Taro cannot concentrate anywhere other than the study, so he always studies in the study.
On this day, however, deliveries addressed to Taro arrive. The arrival time of the -th delivery () is . Taro feels bad making the courier wait at the front door, so he decides to be at the front door at the times the deliveries arrive. The mansion is large, so moving between the study and the front door takes time in each direction.
Meanwhile, Taro wants to study for as long as possible. Find the maximum total time Taro can study in the study between time and time .
Taro is in the study at time , no delivery arrives earlier than time , and no delivery arrives later than time . The time Taro takes to receive a delivery is negligible.
Input
Each dataset consists of 2 lines. The first line contains 3 integers separated by spaces. These integers satisfy , , . The second line contains integers separated by spaces. Each satisfies , and ().
Output
Print on one line the integer representing the maximum total time Taro can study.