logo AlgoBeat OnlineJudge
登录 注册

#216556. [GKS 2015 #E] Sums of Sums

内存限制:1024 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Alice presented her friend Bob with an array of positive integers, indexed from to . She challenged Bob with many queries of the form "what is the sum of the numbers between these two indexes?" But Bob was able to solve the problem too easily.

Alice took her array and found all non-empty subarrays of it. She found the sum of each subarray, and then sorted those values (in nondecreasing order) to create a new array, indexed from to . For example, for an initial array , Alice would generate the subarrays , and (note that , for example, is NOT a subarray). Then she'd take the sums -- -- and sort them to get a new array of .

Alice has given the initial array to Bob, along with queries of the form "what is the sum of the numbers from index to , inclusive, in the new array?" Now Bob's in trouble! Can you help him out?

输入格式

The first line of the input gives the number of test cases, . test cases follow. Each test case begins with one line with two space-separated integers and , denoting the number of elements in the initial array and the number of Alice's queries. Then, there is one line with space-separated integers, denoting the elements of Alice's initial array. Finally, there are more lines with two space-separated integers each: and , the inclusive index bounds for the i-th query.

输出格式

For each test case, output one line with Case #x:, where is the test case number (starting from ). Then output more lines, each with one integer, representing the answers to the queries (in the order they were asked).

样例

样例输入 1

1
5 5
5 4 3 2 1
1 1
1 10
1 15
3 8
4 11

样例输出 1

Case #1:
1
45
105
26
48

数据范围与提示

In sample case #1, Alice's new array would be: .

Limits

.
.
.
.

Small dataset (Test Set 1 - Visible)

.

Large dataset (Test Set 2 - Hidden)

.