spoj#TWOSUMQUERY. Two Sum Query

Two Sum Query

You will be given an array A of size N and also given Q queries. In each query you will be given a number K. You have to print two number S1and S2. Where S1is the sum of all the elements that are strictly less thanK and S2 is the sum of all the elements that are strictly greater than K.

Input

Input starts with an integer T (1<=T<=20) , denoting the number of test cases. Each test case starts with two integers N (1<=N<=105) and Q (1<=Q<=105). N denotes the number of elements in the array and Q is the number of query . The next line contain N integers A0,A1,A2, … , AN-1 (0<=Ai<=109). Then the next line contains Q integers K (0<=K <=109). For each K you have to print S1and S2.

Output

For each test case print “Case X:”(without quotes) where X is the running test case number. Then next Q line consist S1and S2 for every given K in the current test case. Where S1is the sum of all the elements that are strictly less thanK and S2 is the sum of all the elements that are strictly greater than K.

 

Sample Input:

2
10 5
5 1 0 8 1 13 34 21 3 2
1 2 3 4 35
7 2
6 24 120 1 720 2 1
1 23

Sample Output:

Case 1:
0 86
2 84
4 81
7 81
88 0
Case 2:
0 872
10 864