#P9186. [USACO23OPEN] Milk Sum S
[USACO23OPEN] Milk Sum S
题目描述
Note: The time limit for this problem is 4s, 2x the default.
Farmer John's cows have integer milk production values . That is, the th cow produces units of milk per minute.
Each morning, Farmer John starts with all cows hooked up to his milking machine in the barn. He is required to unhook them one by one, sending them out for their daily exercise routine. The first cow he sends out is unhooked after just 1 minute of milking, the second cow he sends out is unhooked after another minute of milking, and so on. Since the first cow (say, cow ) only spends one minute on the milking machine, she contributes only units of total milk. The second cow (say, cow ) spends two total minutes on the milking machine, and therefore contributes units of total milk. The third cow (say, cow ) contributes total units, and so on. Let represent the maximum possible amount of milk, in total, that Farmer John can collect, if he unhooks his cows in an optimal order.
Farmer John is curious how would be affected if some of the milk production values in his herd were different. For each of queries, each specified by two integers and , please calculate what would be the new value of if were set to . Note that each query is considering a temporary potential change independent of all other queries; that is, reverts back to its original value before the next query is considered.
输入格式
The first line contains .
The second line contains .
The third line contains .
The next lines each contain two space-separated integers and .
输出格式
Please print the value of for each of the queries on separate lines.
题目大意
题目描述
注意:本题的时间限制为 4 秒,是默认时间限制的 2 倍。
Farmer John 的 头奶牛的产奶量为整数 。也就是说,第 头奶牛每分钟产 单位的牛奶。
每天早上,Farmer John 会将所有 头奶牛连接到谷仓的挤奶机上。他需要依次断开连接,将奶牛送去进行日常锻炼。第一头奶牛在挤奶 1 分钟后被断开连接,第二头奶牛在再挤奶 1 分钟后被断开连接,依此类推。由于第一头奶牛(假设是奶牛 )只在挤奶机上停留了 1 分钟,她总共贡献了 单位的牛奶。第二头奶牛(假设是奶牛 )在挤奶机上停留了总共 2 分钟,因此贡献了 单位的牛奶。第三头奶牛(假设是奶牛 )贡献了 单位的牛奶,依此类推。设 表示 Farmer John 以最优顺序断开奶牛连接时,可以收集到的最大总牛奶量。
Farmer John 很好奇,如果某些奶牛的产奶量发生变化, 会如何变化。对于每个由两个整数 和 指定的 个查询,请计算如果将 设置为 ,新的 值会是多少。注意,每个查询都是独立的临时变化,即在考虑下一个查询之前, 会恢复为原始值。
输入格式
第一行包含 。
第二行包含 。
第三行包含 。
接下来的 行,每行包含两个用空格分隔的整数 和 。
输出格式
请为每个查询输出一行,表示对应的 值。
提示
对于第一个查询, 将变为 ,此时 $T = 1 \cdot 1 + 2 \cdot 1 + 3 \cdot 2 + 4 \cdot 4 + 5 \cdot 6 = 55$。
对于第二个查询, 将变为 ,此时 $T = 1 \cdot 1 + 2 \cdot 2 + 3 \cdot 4 + 4 \cdot 6 + 5 \cdot 8 = 81$。
对于第三个查询, 将变为 ,此时 $T = 1 \cdot 1 + 2 \cdot 4 + 3 \cdot 5 + 4 \cdot 6 + 5 \cdot 10 = 98$。
,,,。
- 输入 2-4:。
- 输入 5-11:没有额外限制。
5
1 10 4 2 6
3
2 1
2 8
4 5
55
81
98
提示
For the first query, would become , and $T = 1 \cdot 1 + 2 \cdot 1 + 3 \cdot 2 + 4 \cdot 4 + 5 \cdot 6 = 55$.
For the second query, would become , and $T = 1 \cdot 1 + 2 \cdot 2 + 3 \cdot 4 + 4 \cdot 6 + 5 \cdot 8 = 81$.
For the third query, would become , and $T = 1 \cdot 1 + 2 \cdot 4 + 3 \cdot 5 + 4 \cdot 6 + 5 \cdot 10 = 98$.
, ,,.
- Inputs 2-4: .
- Inputs 5-11: No additional constraints.