CF1651F.Tower Defense

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:512MB

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 11 to nn contains a tower in it.

The tower in the ii-th point has cic_i mana capacity and rir_i mana regeneration rate. In the beginning, before the 00-th second, each tower has full mana. If, at the end of some second, the ii-th tower has xx mana, then it becomes min(x+ri,ci)\mathit{min}(x + r_i, c_i) mana for the next second.

There are qq monsters spawning on a level. The jj-th monster spawns at point 11 at the beginning of tjt_j-th second, and it has hjh_j health. Every monster is moving 11 point per second in the direction of increasing coordinate.

When a monster passes the tower, the tower deals min(H,M)\mathit{min}(H, M) damage to it, where HH is the current health of the monster and MM 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 nn towers and remain alive. Monocarp wants to know what will be the total health of the monsters after they pass all towers.

Monocarp 正在玩一款塔防游戏。游戏中的一关可以表示为一条 OXOX 轴,其中从 11 到 nn 的每个整数坐标点上都有一座塔。

第 ii 座塔的法力容量为 cic_i,法力恢复速率为 rir_i。初始时(即第 00 秒之前),每座塔均拥有满法力。若某座塔在某一秒结束时拥有 xx 点法力,则它在下一秒开始时的法力值为 min(x+ri,ci)\mathit{min}(x + r_i, c_i)。

本关中共有 qq 只怪物生成。第 jj 只怪物于第 tjt_j 秒初在坐标点 11 处生成,其生命值为 hjh_j。每只怪物每秒沿坐标增大的方向移动 11 个单位距离。

当一只怪物经过某座塔时,该塔对其造成 min(H,M)\mathit{min}(H, M) 点伤害,其中 HH 是怪物当前的生命值,MM 是该塔当前的法力值。该伤害值将同时从怪物的生命值和塔的法力值中扣除。

不幸的是,有时部分怪物可能成功穿过全部 nn 座塔并依然存活。Monocarp 想知道:所有怪物穿过全部塔之后,它们剩余生命值的总和是多少?

输入格式

The first line contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of towers.

The ii-th of the next nn lines contains two integers cic_i and rir_i (1≤ri≤ci≤1091 \le r_i \le c_i \le 10^9) — the mana capacity and the mana regeneration rate of the ii-th tower.

The next line contains a single integer qq (1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of monsters.

The jj-th of the next qq lines contains two integers tjt_j and hjh_j (0≤tj≤2⋅1050 \le t_j \le 2 \cdot 10^5; 1≤hj≤10121 \le h_j \le 10^{12}) — the time the jj-th monster spawns and its health.

The monsters are listed in the increasing order of their spawn time, so tj<tj+1t_j \lt t_{j+1} for all 1≤j≤q−11 \le j \le q-1.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 塔的数量。

接下来的 nn 行中,第 ii 行包含两个整数 cic_i 和 rir_i(1≤ri≤ci≤1091 \le r_i \le c_i \le 10^9)—— 第 ii 座塔的法力容量与法力恢复速率。

接下来一行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5)—— 怪物的数量。

接下来的 qq 行中,第 jj 行包含两个整数 tjt_j 和 hjh_j(0≤tj≤2⋅1050 \le t_j \le 2 \cdot 10^5;1≤hj≤10121 \le h_j \le 10^{12})—— 第 jj 只怪物的生成时间及其生命值。

怪物按生成时间升序列出,即对所有 1≤j≤q−11 \le j \le q-1,均有 tj<tj+1t_j \lt t_{j+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

输入解题思路,AI测评打分。不知道怎么写?

首页