#P10284. [USACO24OPEN] Splitting Haybales P
[USACO24OPEN] Splitting Haybales P
题目描述
Farmer John wants to fairly split haybales between his two favorite cows Bessie and Elsie. He has ( ) haybales sorted in non-increasing order, where the -th haybale has units of hay ().
Farmer John is considering splitting a contiguous range of haybales between Bessie and Elsie. He has decided to process the haybales in order from to , and when processing the -th haybale he will give it to the cow who currently has less hay (if it is a tie, he will give it to Bessie).
You are given () queries, each with three integers (, ). For each query, output how many more units of hay Bessie will have than Elsie after processing haybales to , if Bessie starts with more units than Elsie. Note that this value is negative if Elsie ends up with more haybales than Bessie.
输入格式
First line contains .
Second line contains .
Third line contains .
Next lines contain .
输出格式
Output lines, containing the answer for each query.
2
3 1
15
1 1 -2
1 1 -1
1 1 0
1 1 1
1 1 2
1 2 -2
1 2 -1
1 2 0
1 2 1
1 2 2
2 2 -2
2 2 -1
2 2 0
2 2 1
2 2 2
1
2
3
-2
-1
0
1
2
-1
0
-1
0
1
0
1
5
4 4 3 1 1
7
1 1 20
1 2 20
1 5 20
1 1 0
1 5 0
1 4 0
3 5 2
16
12
7
4
1
2
1
提示
For Sample 1:
For the 1st query, Elsie starts with more hay than Bessie. Then, after processing haybale , Bessie will receive hay, and Bessie will have more hay than Elsie.
For the 3rd query, Elsie and Bessie start with the same number of hay. After processing haybale , Bessie will receive hay, and Bessie will have more hay than Elsie.
For the 9th query, Bessie starts with more hay than Elsie, then after processing the 1st haybale, has less hay than Elsie, and after processing the 2nd haybale, has less hay than Elsie.
For Sample 2:
In the 5th query, there are haybales to process. Bessie receives hay, then Elsie receives hay, then Bessie receives hay, then Elsie receives hay, then Elsie receives hay.
SCORING:
- Input 3: .
- Inputs 4-6: At most distinct .
- Inputs 7-22: No additional constraints.