欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1162A.Zoning Restrictions Again
Zoning Restrictions Again
You are planning to build housing on a street. There are spots available on the street on which you can build a house. The spots are labeled from to from left to right. In each spot, you can build a house with an integer height between and .
In each spot, if a house has height , you will gain dollars from it.
The city has zoning restrictions. The -th restriction says that the tallest house from spots to (inclusive) must be at most .
You would like to build houses to maximize your profit. Determine the maximum profit possible.
Input
The first line contains three integers , , and () — the number of spots, the maximum height, and the number of restrictions.
Each of the next lines contains three integers , , and (, ) — left and right limits (inclusive) of the -th restriction and the maximum possible height in that range.
Output
Print a single integer, the maximum profit you can make.
Note
In the first example, there are houses, the maximum height of a house is , and there are restrictions. The first restriction says the tallest house between and must be at most . The second restriction says the tallest house between and must be at most . The third restriction says the tallest house between and must be at most .
In this case, it is optimal to build houses with heights . This fits within all the restrictions. The total profit in this case is .
In the second example, there are houses, the maximum height of a house is , and there are restrictions. The first restriction says the tallest house from to must be at most . The second restriction says the tallest house from to must be at most .
In this case, it's optimal to build houses with heights . We get a profit of . Note that there are two restrictions on house and both of them must be satisfied. Also, note that even though there isn't any explicit restrictions on house , we must still limit its height to be at most ().
Samples
3 3 3
1 1 1
2 2 3
3 3 2
14
4 10 2
2 3 8
3 4 7
262
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |