A12942 | Make The Fence Great Again
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You have a fence consisting of $n$ vertical boards. The width of each board is $1$ . The height of the $i$ -th board is $a_i$ . 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 $a_{i-1} \neq a_i$ 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 $b_i$ 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.
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 $b_i$ 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 \le q \le 3 \cdot 10^5$ ) — the number of queries.
The first line of each query contains one integers $n$ ( $1 \le n \le 3 \cdot 10^5$ ) — 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 $a_i$ and $b_i$ ( $1 \le a_i, b_i \le 10^9$ ) — 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 \cdot 10^5$ .
It is guaranteed that answer to each query will not exceed $10^{18}$ .
The first line of each query contains one integers $n$ ( $1 \le n \le 3 \cdot 10^5$ ) — 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 $a_i$ and $b_i$ ( $1 \le a_i, b_i \le 10^9$ ) — 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 \cdot 10^5$ .
It is guaranteed that answer to each query will not exceed $10^{18}$ .
输出格式
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 \cdot b_2 = 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 \cdot b_1 + 1 \cdot b_3 = 9$ .
In the third query the fence is great initially, so you don't need to spend rubles.
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 \cdot b_1 + 1 \cdot b_3 = 9$ .
In the third query the fence is great initially, so you don't need to spend rubles.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted