A13455 | Circle of Monsters
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are playing another computer game, and now you have to slay $n$ monsters. These monsters are standing in a circle, numbered clockwise from $1$ to $n$ . Initially, the $i$ -th monster has $a_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 $1$ (deals $1$ damage to it). Furthermore, when the health of some monster $i$ becomes $0$ or less than $0$ , it dies and explodes, dealing $b_i$ damage to the next monster (monster $i + 1$ , if $i < n$ , or monster $1$ , if $i = 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 $n$ monsters in the circle.
You may shoot the monsters to kill them. Each shot requires exactly one bullet and decreases the health of the targeted monster by $1$ (deals $1$ damage to it). Furthermore, when the health of some monster $i$ becomes $0$ or less than $0$ , it dies and explodes, dealing $b_i$ damage to the next monster (monster $i + 1$ , if $i < n$ , or monster $1$ , if $i = 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 $n$ monsters in the circle.
输入格式
The first line contains one integer $T$ ( $1 \le T \le 150000$ ) — the number of test cases.
Then the test cases follow, each test case begins with a line containing one integer $n$ ( $2 \le n \le 300000$ ) — the number of monsters. Then $n$ lines follow, each containing two integers $a_i$ and $b_i$ ( $1 \le a_i, b_i \le 10^{12}$ ) — the parameters of the $i$ -th monster in the circle.
It is guaranteed that the total number of monsters in all test cases does not exceed $300000$ .
Then the test cases follow, each test case begins with a line containing one integer $n$ ( $2 \le n \le 300000$ ) — the number of monsters. Then $n$ lines follow, each containing two integers $a_i$ and $b_i$ ( $1 \le a_i, b_i \le 10^{12}$ ) — the parameters of the $i$ -th monster in the circle.
It is guaranteed that the total number of monsters in all test cases does not exceed $300000$ .
输出格式
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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted