CF1221D.Make The Fence Great Again
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a fence consisting of n vertical boards. The width of each board is 1 . The height of the i -th board is ai . You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from 2 to n , the condition ai−1=ai holds.
Unfortunately, it is possible that now your fence is not great. But you can change it! You can increase the length of the i -th board by 1 , but you have to pay bi rubles for it. The length of each board can be increased any number of times (possibly, zero).
Calculate the minimum number of rubles you have to spend to make the fence great again!
You have to answer q independent queries.
输入格式
The first line contains one integer q ( 1≤q≤3⋅105 ) — the number of queries.
The first line of each query contains one integers n ( 1≤n≤3⋅105 ) — the number of boards in the fence.
The following n lines of each query contain the descriptions of the boards. The i -th line contains two integers ai and bi ( 1≤ai,bi≤109 ) — the length of the i -th board and the price for increasing it by 1 , respectively.
It is guaranteed that sum of all n over all queries not exceed 3⋅105 .
It is guaranteed that answer to each query will not exceed 1018 .
输出格式
For each query print one integer — the minimum number of rubles you have to spend to make the fence great.
输入输出样例
输入#1
3 3 2 4 2 1 3 5 3 2 3 2 10 2 6 4 1 7 3 3 2 6 1000000000 2
输出#1
2 9 0
说明/提示
In the first query you have to increase the length of second board by 2 . So your total costs if 2⋅b2=2 .
In the second query you have to increase the length of first board by 1 and the length of third board by 1 . So your total costs if 1⋅b1+1⋅b3=9 .
In the third query the fence is great initially, so you don't need to spend rubles.