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 S
1
and S
2
. Where S
1
is the sum of all the elements that are strictly less thanK
and S
2
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
<=10
5
) and Q
(1
<=Q
<=10
5
). N
denotes the number of elements in the array and Q
is the number of query . The next line contain N
integers A
0
,A
1
,A
2
, … , A
N-1
(0
<=A
i
<=10
9
). Then the next line contains Q integers K
(0
<=K
<=10
9
). For each K
you have to print S
1
and S
2
.
Output
For each test case print “Case X:”
(without quotes) where X
is the running test case number. Then next Q
line consist S
1
and S
2
for every given K
in the current test case. Where S
1
is the sum of all the elements that are strictly less thanK
and S
2
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