This page is still under construction.

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

A Weighty Problem

Time limit1sMemory limit128 MB

Summary
Choose which coins to hand over for a purchase so that the total weight of unspent coins plus the store's greedy change is minimized.
Level

Hard8 of 10

Topics
Dynamic programming, Greedy, Math, Implementation
Solved
No attempts yet

Problem

You like to pay with coins, but you have a problem: you carry so much loose change that your pocket has grown too heavy. You have a plan to lighten it, and you need a program to carry it out.

Your next purchase costs CC cents. You will hand over some of your coins whose total value is at least CC; if you overpay, the store gives you change. Choose which coins to spend so that the total weight of the coins left in your pocket afterward — the coins you did not spend, plus the coins the store hands back as change — is as small as possible.

When the store owes you XX cents it makes change greedily: it repeatedly gives you one coin of the largest denomination whose value is at most XX, subtracts that value from XX, and continues until XX reaches 00. The store has an unlimited supply of every denomination.

There are DD denominations. Denomination ii has an integer value ViV_i (in cents) and a weight WiW_i (in grams). Exactly one denomination has value 11, and no two denominations share a value.

You own KK coins; coin jj is of denomination DjD_j.

Constraints: 1≤C≤1000001 \le C \le 100000, 1≤D≤1001 \le D \le 100, 1≤K≤1001 \le K \le 100, 1≤Vi≤20001 \le V_i \le 2000, 0<Wi<100 < W_i < 10 (given to two decimal places), and 1≤Dj≤D1 \le D_j \le D.

Input

The first line contains three integers CC, DD, and KK: the cost of the purchase in cents, the number of coin denominations, and the number of coins you own.

Each of the next DD lines contains an integer ViV_i and a real number WiW_i (given to exactly two decimal places): the value in cents and the weight in grams of denomination ii.

Each of the next KK lines contains one integer DjD_j: the 1-based denomination of the jj-th coin you own.

Output

If you can afford the purchase, print the minimum achievable total weight in grams, rounded to two decimal places (the answer is always an exact multiple of 0.010.01). Otherwise, print too poor.

Hint

Suppose you own seven 5-cent coins and are buying something for 3 cents, with denominations of 1, 5, 10, and 20 cents weighing 1, 2, 1, and 9 grams respectively.

One optimal choice is to spend three 5-cent coins: the store then owes you 12 cents and returns one 10-cent coin and two 1-cent coins. Another is to spend four 5-cent coins: the store owes you 17 cents and returns one 10-cent coin, one 5-cent coin, and two 1-cent coins. Both leave 11.0011.00 grams in your pocket.

Examples3

  1. Example 1

    Input
    3 4 7
    1 1.00
    5 2.00
    20 9.00
    10 1.00
    2
    2
    2
    2
    2
    2
    2
    
    Expected output
    11.00
    
  2. Example 2

    Input
    100 1 1
    1 5.00
    1
    
    Expected output
    too poor
    
  3. Example 3

    Input
    5 2 1
    1 1.00
    5 3.00
    2
    
    Expected output
    0.00