#PS0000250. Điểm số cao nhất (High Score)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Điểm số cao nhất (High Score)
High Score
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Takahashi plays a game with ruins and gem types numbered from 1 to . He may explore ruins in any order, at most once per ruin. Exploring ruin awards points and one gem of every type in the inclusive interval . Gems cannot be discarded. Acquiring all types revives the demon king and cancels the score of the ruin being explored. Takahashi wants to choose ruins so that the demon king never revives and his total score is maximized. Exploring no ruins is allowed. Find the maximum score.
Input
First line: integers . Each of the next lines contains three integers .
Output
Print one integer: the maximum score without reviving the demon king.
Subtasks
- Subtask 1 (30 points): ; ; .
- Subtask 2 (69 points): ; ; .
- Subtask 3 (1 points): ; ; .
Example 1
Input
4 6
1 3 30
2 3 40
3 6 25
6 6 10
Output
80
Explanation
Choose ruins 1, 2 and 4 for 80 points, leaving types 4 and 5 missing. No choice leaving a type missing exceeds 80.
Example 2
Input
2 7
1 3 90
5 7 90
Output
180
Explanation
Explore both ruins, leaving type 4 missing and earning 180 points.
Example 3
Input
1 4
1 4 70
Output
0
Explanation
The only ruin contains all four types, so it cannot be explored.