A1225 | [COCI-2011_2012-contest2]#5 RASPORED
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Mirko’s pizza place is the best one in town. It is so good that all town residents eat pizza for lunch every day. Mirko’s delivery service is so fast that the delivery time is negligible. The problem is baking the pizzas, since all residents have their own favourite topping combination, so baking pizzas for two different residents doesn’t always take the same amount of time. Mirko only has one small baking oven with a capacity of a single pizza at a time, so good scheduling is extremely important and must be determined before the day starts.
For each of the N town residents (denoted by numbers from 1 to N) we know the baking duration for their favourite pizza (Ti), as well as the moment in the day when they plan on having lunch (Li). If a resident receives their pizza K moments before the planned lunch time, Mirko is rewarded with a tip of K kunas
1. On the other hand, if the pizza is delivered K moments late (after the planned lunch time), Mirko must pay the resident K kunas (because of his timely delivery insurance policy). If the pizza is delivered precisely on time, Mirko won’t get a tip, but he doesn’t have to pay anything either.
Mirko would like to know the maximum total tip (including all insurance payouts as negative tips)
that can be earned in a day if pizzas are baked in an optimal order. Notice that Mirko can earn a negative total tip (if he has to pay out more insurance than the amount of tips he receives).
Since residents sometimes change their favourite pizza toppings, as well as their preferred lunch time, Mirko’s schedule must be adapted in order to keep earning optimal tip amounts. Write a program to compute the maximum total tip for the beginning requirements, as well as after each change.
Note: In this town, the day starts at the moment t = 0 and lasts much longer than the time needed to bake pizzas for all residents. The schedule, including the adaptations, must be determined before the day starts.
For each of the N town residents (denoted by numbers from 1 to N) we know the baking duration for their favourite pizza (Ti), as well as the moment in the day when they plan on having lunch (Li). If a resident receives their pizza K moments before the planned lunch time, Mirko is rewarded with a tip of K kunas
1. On the other hand, if the pizza is delivered K moments late (after the planned lunch time), Mirko must pay the resident K kunas (because of his timely delivery insurance policy). If the pizza is delivered precisely on time, Mirko won’t get a tip, but he doesn’t have to pay anything either.
Mirko would like to know the maximum total tip (including all insurance payouts as negative tips)
that can be earned in a day if pizzas are baked in an optimal order. Notice that Mirko can earn a negative total tip (if he has to pay out more insurance than the amount of tips he receives).
Since residents sometimes change their favourite pizza toppings, as well as their preferred lunch time, Mirko’s schedule must be adapted in order to keep earning optimal tip amounts. Write a program to compute the maximum total tip for the beginning requirements, as well as after each change.
Note: In this town, the day starts at the moment t = 0 and lasts much longer than the time needed to bake pizzas for all residents. The schedule, including the adaptations, must be determined before the day starts.
输入格式
The first line of input contains two positive integers N and C, the number of residents and the number of pizza requirement changes, respectively.
Each of the next N lines contains two positive integers: Li, the moment when resident i plans on having lunch, and Ti, the time needed to bake the pizza for resident i.
Each of the next C lines contains three positive integers: R (the index of a resident), L (the new moment when resident R plans on having lunch), and T (the time needed to bake resident R’s new favourite pizza).
Constraints:
1 ≤ N, C ≤ 200 000,
0 ≤ Li, L ≤ 100 000,
1 ≤ Ti, T ≤ 100 000,
1 ≤ R ≤ N.
Each of the next N lines contains two positive integers: Li, the moment when resident i plans on having lunch, and Ti, the time needed to bake the pizza for resident i.
Each of the next C lines contains three positive integers: R (the index of a resident), L (the new moment when resident R plans on having lunch), and T (the time needed to bake resident R’s new favourite pizza).
Constraints:
1 ≤ N, C ≤ 200 000,
0 ≤ Li, L ≤ 100 000,
1 ≤ Ti, T ≤ 100 000,
1 ≤ R ≤ N.
输出格式
The first line of output must contain the maximum total tip for the beginning requirements of the residents.
For each of the C changes, the output must contain an additional line of output containing the new maximum total tip value after the change.
For each of the C changes, the output must contain an additional line of output containing the new maximum total tip value after the change.
输入输出样例
输入 #1
3 2 10 2 6 5 4 3 1 6 1 3 0 10
输出 #1
3 2 -11
输入 #2
4 2 3 2 0 3 4 3 4 1 3 0 4 1 4 5
输出 #2
-8 -13 -18
输入 #3
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
输出 #3
27 59 56 69 78 81 82 58
In test cases worth 50% of points, the following constraint holds: 1 ≤ Ti
, T ≤ 1000.
First sample description: The optimal pizza baking schedule is (1, 3, 2). That way, the first pizza will
be finished at the moment t = 2, the third one at t = 5, and the second one at t = 10. The first pizza
will be delivered 8 moments early (8 kunas tip), the second one will be 1 moment late (-1 kuna), and the
third one will be 4 moments late (-4 kunas), so the total tip is 3 kunas. When the first resident changes
requirements, the optimal schedule remains unchanged, while the tips change to 5, 0, and -3,
respectively. After the second requirement change, the optimal schedule is (1, 2, 3), while the tips are 5,
0, and -16, respectively.
, T ≤ 1000.
First sample description: The optimal pizza baking schedule is (1, 3, 2). That way, the first pizza will
be finished at the moment t = 2, the third one at t = 5, and the second one at t = 10. The first pizza
will be delivered 8 moments early (8 kunas tip), the second one will be 1 moment late (-1 kuna), and the
third one will be 4 moments late (-4 kunas), so the total tip is 3 kunas. When the first resident changes
requirements, the optimal schedule remains unchanged, while the tips change to 5, 0, and -3,
respectively. After the second requirement change, the optimal schedule is (1, 2, 3), while the tips are 5,
0, and -16, respectively.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted