Counting Pair
Time Limit: 1000 ms Memory Limit: 65535 kB Solved: 112 Tried: 1209
Description
Bob hosts a party and invites N boys and M girls. He gives every boy here a unique number Ni(1 <= Ni <= N). And for the girl, everyone holds a unique number Mi(1 <= Mi <= M), too.
Now when Bob name a number X, if a boy and a girl wants and their numbers' sum equals to X, they can get in pair and dance.
At this night, Bob will name Q numbers, and wants to know the maxinum pairs could dance in each time. Can you help him?
Input
First line of the input is a single integer T(1 <= T <= 30), indicating there are T test cases.
The first line of each test case contains two numbers N and M(1 <= N,M <= 100000).
The second line contains a single number Q(1 <= Q <= 100000).
Each of the next Q lines contains one number X(0 <= X <= 10^9), indicating the number Bob names.
Output
For each test case, print "Case #t:" first, in which t is the number of the test case starting from 1.
Then for each number Bob names, output a single num in each line, which shows the maxinum pairs that could dance together.
Sample Input
1
4 5
3
1
2
3
Sample Output
Case #1:
0
1
2
Hint
This problem has very large input data. scanf and printf are recommended for C++ I/O.
Source
Sichuan State Programming Contest 2012
1 #include 2 #include 3 #include 4 #include