CF1334C.Circle of Monsters
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ai 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 bi 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≤T≤150000 ) — the number of test cases.
Then the test cases follow, each test case begins with a line containing one integer n ( 2≤n≤300000 ) — the number of monsters. Then n lines follow, each containing two integers ai and bi ( 1≤ai,bi≤1012 ) — 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