This page is still under construction.

Parts of this page are still being built. What you see may change.

Diana and the Golden Apples

Interview

Time limit2sMemory limit256 MB

Summary
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 LL units of 100 m long. Carrying nothing, Diana runs 100 m in TdT_d seconds, and Humperdonkey runs 100 m in ThT_h seconds. Humperdonkey never picks up an apple.

Apple ii lies xix_i units of 100 m from the start and weighs wiw_i 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 dd extra seconds per 100 m, so picking up apple ii adds d×wi×(L−xi)d \times w_i \times (L - x_i) seconds to her total time.

If Diana picks up the set of apples SS, her time is L×Td+∑i∈Sd×wi×(L−xi)L \times T_d + \sum_{i \in S} d \times w_i \times (L - x_i) seconds and Humperdonkey's time is L×ThL \times T_h 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 LL, TdT_d, ThT_h, NN and dd. (1≤L≤10001 \le L \le 1000, 10≤Td≤3010 \le T_d \le 30, 10≤Th≤3010 \le T_h \le 30, 0≤N≤10000 \le N \le 1000, 0<d≤100 < d \le 10)

Each of the next NN lines describes one apple with two space separated integers wiw_i and xix_i. (0<wi≤500 < w_i \le 50, 0≤xi<L0 \le x_i < L)

Several apples can lie at the same point.

Output

Print on one line the largest weight of gold WW 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

Examples2

  1. Example 1

    Input
    20 10 16 4 2
    2 8
    3 9
    4 10
    30 18
    
    Expected output
    5
    
  2. Example 2

    Input
    16 18 18 0 2
    
    Expected output
    Diana marries Humperdonkey