문제
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.
예제 입력 1
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
1
2
3
-2
-1
0
1
2
-1
0
-1
0
1
0
1
예제 입력 2
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
예제 출력 2
16
12
7
4
1
2
1
점수
Input 3: Inputs 4-6: At most distinct Inputs 7-22: No additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인