All submissions for this problem are available.
Saurabh and Pranav play the popular game of Hungry Birds on windows and android phones respectively.
The game goal is to destroy birds in the Hungry Birds Game. A certain number of points is given for destroying each bird depending on the bird type and the current factor value.
There are n types of Hungry Birds. The number of birds of type ai and bird cost ci is known for each bird type. A player gets ci.f points for destroying one bird of type i, where f is the current factor. The factor value can be an integer number from 1 to t + 1, inclusive. At the beginning of the game the factor value is equal to 1. The factor is set to i + 1 after destruction of pi (1 ≤ i ≤ t) birds, so the (pi + 1)-th bird to be destroyed is considered with factor equal to i + 1.
Your task is to determine the maximum number of points Saurabh and Pranav can get after they destroy all birds. Take into account that they are so tough that they can destroy birds in any order chosen by them individually on their respective phones.
The first line contains the only integer number n (1 ≤ n ≤ 100) — the number of bird types.
Each of the following n lines contains two integer numbers ai and ci (1 ≤ ai ≤ 10^9, 0 ≤ ci ≤ 1000), separated with space — the number of birds of the i-th type and the cost of one i-type bird, correspondingly.
The next line contains the only integer number t (1 ≤ t ≤ 100) — the number that describe the factor's changes.
The next line contains t integer numbers pi (1 ≤ p1 < p2 < ... < pt ≤ 10^12), separated with spaces.
Print the only number — the maximum number of points they can get.
Input: 2 3 8 5 10 1 20 Output: 74
|Time Limit:||0.5 - 1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.