CF1651F.Tower Defense
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Monocarp is playing a tower defense game. A level in the game can be represented as an OX axis, where each lattice point from 1 to n contains a tower in it.
The tower in the i -th point has ci mana capacity and ri mana regeneration rate. In the beginning, before the 0 -th second, each tower has full mana. If, at the end of some second, the i -th tower has x mana, then it becomes min(x+ri,ci) mana for the next second.
There are q monsters spawning on a level. The j -th monster spawns at point 1 at the beginning of tj -th second, and it has hj health. Every monster is moving 1 point per second in the direction of increasing coordinate.
When a monster passes the tower, the tower deals min(H,M) damage to it, where H is the current health of the monster and M is the current mana amount of the tower. This amount gets subtracted from both monster's health and tower's mana.
Unfortunately, sometimes some monsters can pass all n towers and remain alive. Monocarp wants to know what will be the total health of the monsters after they pass all towers.
输入格式
The first line contains a single integer n ( 1≤n≤2⋅105 ) — the number of towers.
The i -th of the next n lines contains two integers ci and ri ( 1≤ri≤ci≤109 ) — the mana capacity and the mana regeneration rate of the i -th tower.
The next line contains a single integer q ( 1≤q≤2⋅105 ) — the number of monsters.
The j -th of the next q lines contains two integers tj and hj ( 0≤tj≤2⋅105 ; 1≤hj≤1012 ) — the time the j -th monster spawns and its health.
The monsters are listed in the increasing order of their spawn time, so tj<tj+1 for all 1≤j≤q−1 .
输出格式
Print a single integer — the total health of all monsters after they pass all towers.
输入输出样例
输入#1
3 5 1 7 4 4 2 4 0 14 1 10 3 16 10 16
输出#1
4
输入#2
5 2 1 4 1 5 4 7 5 8 3 9 1 21 2 18 3 14 4 24 5 8 6 25 7 19 8 24 9 24
输出#2
40