#P5851. [USACO19DEC] Greedy Pie Eaters P
[USACO19DEC] Greedy Pie Eaters P
Description
Farmer John has cows, conveniently labeled , who enjoy the occasional change of pace from eating grass. As a treat for the cows, Farmer John has baked pies (), labeled . Cow enjoys pies with labels in the range (from to inclusive), and no two cows enjoy the exact same range of pies. Cow also has a weight, , which is an integer in the range .
Farmer John may choose a sequence of cows after which the selected cows will take turns eating in that order. Unfortunately, the cows don't know how to share! When it is cow 's turn to eat, she will consume all of the pies that she enjoys --- that is, all remaining pies in the interval . Farmer John would like to avoid the awkward situation occurring when it is a cows turn to eat but all of the pies she enjoys have already been consumed. Therefore, he wants you to compute the largest possible total weight () of a sequence for which each cow in the sequence eats at least one pie.
Input Format
The first line contains two integers and
The next lines each describe a cow in terms of the integers ,, and .
Output Format
Print the maximum possible total weight of a valid sequence.
2 2
100 1 2
100 1 1
200
Hint
In this example, if cow eats first, then there will be nothing left for cow to eat. However, if cow eats first, then cow will be satisfied by eating the second pie only.
Test cases satisfy and .
Test cases satisfy .
京公网安备 11011102002149号