Splitting Haybales
시간 제한2초메모리 제한1024 MB
각 질의마다 부분 배열에서 현재 더 적게 가진 소에게 건초를 차례로 주며, 시작 차이 x일 때 최종 차이를 구한다.
문제
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.