Dormitory Parcel Delivery
Time limit1sMemory limit1024 MB
Find the minimum time to start at the storage room, deliver every parcel, and return, when carried weight slows the walking speed to 1/(1+W).
- Level
Hard9 of 10
- Topics
- Dynamic programming, Divide and conquer, Sorting
- Solved
- No attempts yet
Problem
A dormitory of the Korea Science Academy has an entrance and rooms arranged in a straight line. The -th room from the left is room , and the entrance is to the left of room . The distance between the entrance and room is meters. Room is used as the parcel storage room.
Yesung has accumulated too many demerit points, so he has to deliver the parcels in the storage room. parcels are kept in the storage room, and the -th parcel must be delivered to room and weighs . His goal is to start from the storage room, deliver every parcel, and return to the storage room. Taking a parcel out of the storage room or putting it at its destination takes no time.
Yesung can carry any number of parcels at once with no limit. He does not have to take all the parcels at the start, and he can come back to the storage room along the way to fetch some of them. He may choose the order of deliveries freely, but he cannot leave a parcel temporarily at a place other than its destination. When Yesung carries no parcels, he moves at 1 meter per second. If the total weight of the parcels he carries is , his speed drops to meters per second.
Yesung is busy proving P=NP, so find the minimum number of seconds needed to reach the goal.
Input
The first line contains two integers and , separated by a space.
The second line contains integers , separated by spaces.
From the third line onward, the next lines describe the parcels. The -th of these lines contains two integers and , separated by a space.
Output
Print the answer to the problem. Under the given conditions, the answer is guaranteed to be an integer.