CF175C.Geometry Horse

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn types of geometric figures. The number of figures of type kik_{i} and figure cost cic_{i} is known for each figure type. A player gets cifc_{i}·f points for destroying one figure of type ii , where ff is the current factor. The factor value can be an integer number from 11 to t+1t+1 , inclusive. At the beginning of the game the factor value is equal to 1. The factor is set to i+1i+1 after destruction of pip_{i} (1<=i<=t)(1<=i<=t) figures, so the (pi+1)(p_{i}+1) -th figure to be destroyed is considered with factor equal to i+1i+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.

输入格式

The first line contains the only integer number nn (1<=n<=100)(1<=n<=100) — the number of figure types.

Each of the following nn lines contains two integer numbers kik_{i} and cic_{i} (1<=ki<=109,0<=ci<=1000)(1<=k_{i}<=10^{9},0<=c_{i}<=1000) , separated with space — the number of figures of the ii -th type and the cost of one ii -type figure, correspondingly.

The next line contains the only integer number tt (1<=t<=100)(1<=t<=100) — the number that describe the factor's changes.

The next line contains tt integer numbers pip_{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.

输出格式

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

输入输出样例

  • 输入#1

    1
    5 10
    2
    3 6
    

    输出#1

    70
  • 输入#2

    2
    3 8
    5 10
    1
    20
    

    输出#2

    74

说明/提示

In the first example Vasya destroys three figures first and gets 3110=303·1·10=30 points. Then the factor will become equal to 22 and after destroying the last two figures Vasya will get 2210=402·2·10=40 points. As a result Vasya will get 7070 points.

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

首页