欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1621B.Integers Shop
Integers Shop
CF1621B · Integers Shop
- 难度:1500
- 标签:data structures、greedy、implementation
- 链接:https://codeforces.com/problemset/problem/1621/B
- 时间限制:2 seconds 内存限制:256 megabytes
- 出现位置:Day03-贪心证明-排序-交换论证/选做
英文原题面
Statement
The integers shop sells segments. The -th of them contains all integers from to and costs coins. Tomorrow Vasya will go to this shop and will buy some segments there. He will get all integers that appear in at least one of bought segments. The total cost of the purchase is the sum of costs of all segments in it. After shopping, Vasya will get some more integers as a gift. He will get integer as a gift if and only if all of the following conditions are satisfied:
- Vasya hasn't bought .
- Vasya has bought integer that is less than .
- Vasya has bought integer that is greater than .
Vasya can get integer as a gift only once so he won't have the same integers after receiving a gift. For example, if Vasya buys segment for coins and segment for coins, he spends coins and receives integers from these segments. He also gets integers and as a gift. Due to the technical issues only the first segments (that is, segments ) will be available tomorrow in the shop. Vasya wants to get (to buy or to get as a gift) as many integers as possible. If he can do this in differents ways, he selects the cheapest of them. For each from to , find how many coins will Vasya spend if only the first segments will be available.
Input
The first line contains a single integer () — the number of test cases. The first line of each test case contains the single integer () — the number of segments in the shop. Each of next lines contains three integers , , ($1 \leq l_i \leq r_i \leq 10^9, 1 \leq c_i \leq 10^9$) — the ends of the -th segments and its cost. It is guaranteed that the total sum of over all test cases doesn't exceed .
Output
For each test case output integers: the -th () of them should be the number of coins Vasia will spend in the shop if only the first segments will be available.
样例
样例 1
输入:
3
2
2 4 20
7 8 22
2
5 11 42
5 11 42
6
1 4 4
5 8 9
7 8 7
2 10 252
1 11 271
1 10 1
输出:
20
42
42
42
4
13
11
256
271
271
样例解释(英文原文)
In the first test case if then Vasya can buy only the segment for coins and get integers. The way to get integers for coins in case is described in the statement. In the second test case note, that there can be the same segments in the shop.
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |