#P7619. [COCI 2011/2012 #2] RASPORED
[COCI 2011/2012 #2] RASPORED
Description
Mirko’s pizza shop is the best in town, and all residents eat pizza for lunch every day. Also, Mirko’s delivery service is very fast, so the delivery time can be ignored. However, Mirko has only one small oven, and he can bake only one pizza at a time.
We number the residents in the town from to . The time when resident plans to eat lunch is , and the time Mirko needs to bake their pizza is .
If a resident receives their pizza time units before their planned lunch time, Mirko gets a tip of dollars. Similarly, if a resident receives their pizza time units after their planned lunch time, Mirko must pay the resident dollars. If the pizza is delivered exactly on time, Mirko gets no tip and pays nothing.
Please help Mirko arrange the baking order for the day so that the total tip (profit) for the day is maximized.
Notes:
-
The day starts at time unit , and you may assume the day is infinitely long.
-
Residents sometimes change their .
Input Format
The first line contains two positive integers , representing the number of residents and the number of pizza-demand changes.
The next lines each contain two integers .
The next lines each contain three positive integers , representing the index of the resident to change, the new , and the new .
Output Format
The first line contains one integer, the maximum total tip Mirko can get before any modifications.
Then, for each modification, output one line with one integer, the maximum total tip after this modification.
3 2
10 2
6 5
4 3
1 6 1
3 0 10
3
2
-11
4 2
3 2
0 3
4 3
4 1
3 0 4
1 4 5
-8
-13
-18
6 7
17 5
26 4
5 5
12 4
8 1
18 2
3 31 3
4 11 5
4 19 3
5 23 2
6 15 1
5 19 1
3 10 4
27
59
56
69
78
81
82
58
Hint
Sample 1 Explanation
The optimal baking order is . Then, pizza is delivered at time unit , pizza is delivered at time unit , and pizza is delivered at time unit .
Pizza is delivered time units early, so Mirko gets a tip of dollars; pizza is delivered time unit late, so Mirko must pay dollar; pizza is delivered time units late, so Mirko must pay dollars. Therefore, the maximum total tip is .
After the first modification, the baking order does not change, and the tips become .
After the second modification, the baking order becomes , and the tips become .
Constraints
For of the testdata, .
For of the testdata, , , , .
Notes
The score for this problem follows the original COCI settings, with a full score of .
Translated from COCI2011-2012 CONTEST #2 T6 RASPORED.
Translated by ChatGPT 5
京公网安备 11011102002149号