Codeforces Round 115
C
Geometry Horse
Codeforces
1600
原题
← BD →
翻译中…

Vasya plays the Geometry Horse.

翻译中…

The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value.

翻译中…

There are $*n*$ types of geometric figures. The number of figures of type $*k*_{*i*}$ and figure cost $*c*_{*i*}$ is known for each figure type. A player gets $*c*_{*i*}·*f*$ points for destroying one figure 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 $*p*_{*i*}$ $(1 ≤ *i* ≤ *t*)$ figures, so the $(*p*_{*i*} + 1)$-th figure to be destroyed is considered with factor equal to $*i* + 1$.

翻译中…

Your task is to determine the maximum number of points Vasya can get after he destroys all figures. Take into account that Vasya is so tough that he can destroy figures in any order chosen by him.

翻译中…

Input

翻译中…

The first line contains the only integer number $*n*$ $(1 ≤ *n* ≤ 100)$ — the number of figure types.

翻译中…

Each of the following $*n*$ lines contains two integer numbers $*k*_{*i*}$ and $*c*_{*i*}$ $(1 ≤ *k*_{*i*} ≤ 10^{9}, 0 ≤ *c*_{*i*} ≤ 1000)$, separated with space — the number of figures of the $*i*$-th type and the cost of one $*i*$-type figure, 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 $*p*_{*i*}$ $(1 ≤ *p*_{1} < *p*_{2} < ... < *p*_{*t*} ≤ 10^{12})$, separated with spaces.

翻译中…

Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

翻译中…

Output

翻译中…

Print the only number — the maximum number of points Vasya can get.

翻译中…

Note

翻译中…

In the first example Vasya destroys three figures first and gets $3·1·10 = 30$ points. Then the factor will become equal to $2$ and after destroying the last two figures Vasya will get $2·2·10 = 40$ points. As a result Vasya will get $70$ points.

翻译中…

In the second example all $8$ figures will be destroyed with factor $1$, so Vasya will get $(3·8 + 5·10)·1 = 74$ points.

翻译中…

样例

Input #1
1
5 10
2
3 6
Output #1
70
InputCopy OutputCopy
Input #2
2
3 8
5 10
1
20
Output #2
74
InputCopy OutputCopy
题目信息
题号
175C
时间限制
2 s
内存限制
256 MB
标签
贪心
模拟
排序
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。