CF1334C.Circle of Monsters

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are playing another computer game, and now you have to slay nn monsters. These monsters are standing in a circle, numbered clockwise from 11 to nn. Initially, the ii-th monster has aia_i health.

You may shoot the monsters to kill them. Each shot requires exactly one bullet and decreases the health of the targeted monster by 11 (deals 11 damage to it). Furthermore, when the health of some monster ii becomes 00 or less than 00, it dies and explodes, dealing bib_i damage to the next monster (monster i+1i + 1, if i<ni \lt n, or monster 11, if i=ni = n). If the next monster is already dead, then nothing happens. If the explosion kills the next monster, it explodes too, damaging the monster after it and possibly triggering another explosion, and so on.

You have to calculate the minimum number of bullets you have to fire to kill all nn monsters in the circle.

你正在玩另一款电脑游戏,现在你需要消灭 nn 个怪物。这些怪物围成一个圆圈,按顺时针方向编号为 11 到 nn。初始时,第 ii 个怪物的生命值为 aia_i。

你可以向怪物射击以消灭它们。每次射击恰好消耗一颗子弹,并使被击中的怪物生命值减少 11(即造成 11 点伤害)。此外,当某个怪物 ii 的生命值降至 00 或更低时,它会死亡并爆炸,对下一个怪物(若 i<ni < n,则为怪物 i+1i + 1;若 i=ni = n,则为怪物 11)造成 bib_i 点伤害。如果下一个怪物已经死亡,则不会发生任何事。如果爆炸导致下一个怪物死亡,该怪物也会爆炸,进而伤害其后的怪物,并可能引发连锁爆炸,依此类推。

你需要计算在圆圈中消灭全部 nn 个怪物所需的最少子弹数量。

输入格式

The first line contains one integer TT (1≤T≤1500001 \le T \le 150000) — the number of test cases.

Then the test cases follow, each test case begins with a line containing one integer nn (2≤n≤3000002 \le n \le 300000) — the number of monsters. Then nn lines follow, each containing two integers aia_i and bib_i (1≤ai,bi≤10121 \le a_i, b_i \le 10^{12}) — the parameters of the ii-th monster in the circle.

It is guaranteed that the total number of monsters in all test cases does not exceed 300000300000.

第一行包含一个整数 TT(1≤T≤1500001 \le T \le 150000)——测试用例的数量。

接下来是各测试用例。每个测试用例以一行开始,该行包含一个整数 nn(2≤n≤3000002 \le n \le 300000)——怪物的数量。随后是 nn 行,每行包含两个整数 aia_i 和 bib_i(1≤ai,bi≤10121 \le a_i, b_i \le 10^{12})——表示圆圈中第 ii 个怪物的参数。

保证所有测试用例中怪物的总数不超过 300000300000。

输出格式

For each test case, print one integer — the minimum number of bullets you have to fire to kill all of the monsters.

对于每个测试用例,输出一个整数——即杀死所有怪物所需的最少子弹数量。

输入输出样例

  • 输入#1

    1
    3
    7 15
    2 14
    5 3

    输出#1

    6

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

首页