Diana and the Golden Apples
InterviewTime limit2sMemory limit256 MB
Pick the apples with the greatest total weight so the extra carrying time stays strictly below her lead over Humperdonkey.
- Level
Medium4 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
The Roman huntress Diana runs fast. She has agreed to marry any man who beats her in a race, or even matches her time. Prince Humperdonkey of Troy plans to win by leaving golden apples along the track, betting that Diana will slow herself down picking them up. Diana wants to marry nobody at present, and Humperdonkey least of all, and she works out exactly how much gold she can carry and still win. You are Diana. Stay single and collect as much gold as you can.
The race is units of 100 m long. Carrying nothing, Diana runs 100 m in seconds, and Humperdonkey runs 100 m in seconds. Humperdonkey never picks up an apple.
Apple lies units of 100 m from the start and weighs kg. Diana chooses freely which apples to pick up, and she carries every apple she picks up all the way to the finish line. Picking up an apple takes no time. Each kilogram of gold she carries costs her extra seconds per 100 m, so picking up apple adds seconds to her total time.
If Diana picks up the set of apples , her time is seconds and Humperdonkey's time is seconds. Diana wins only when her time is smaller than his. Equal times mean she has to marry him.
Find the largest total weight of gold Diana can be carrying when she crosses the finish line and still wins.
Input
The first line contains five space separated integers , , , and . (, , , , )
Each of the next lines describes one apple with two space separated integers and . (, )
Several apples can lie at the same point.
Output
Print on one line the largest weight of gold that Diana can be carrying while she finishes ahead of Prince Humperdonkey. If Diana cannot beat Humperdonkey, print the following line instead.
Diana marries Humperdonkey