시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 253 | 213 | 174 | 92.063% |
Every day Farmer John feeds the cows a lavish meal of premium gourmet hay. He then records the number of bales on the next line of his expense notebook.
When tax time comes, FJ realizes that he neglected to record the dates for the hay feedings. He must calculate a number of different totals of successive hay feedings in order to solve the puzzle of which feedings went with which month of expenses.
FJ has created a dataset with N (4 <= N <= 500) days conveniently numbered 1..N of hay bale counts H_i (1 <= H_i <= 1,000). He has an additional Q (1 <= Q <= 500) queries -- each query is a pair of integers S_j and E_j (1 <= S_j <= E_j <= N) that denote that start and end indices of some hay bale counts. Your job is to sum the hay bale counts for the days S_j..E_j (inclusive) and report one sum for each query.
4 2 5 8 12 6 1 3 2 4
25 26
Days: 1 2 3 4 Counts: 5 8 12 6 query 1..3: 5 + 8 + 12 = 25 query 2..4: 8 + 12 + 6 = 26