In the secret book of ACM, it’s said: “Glory for those who write short ICPC problems. May they live long, and never get Wrong Answers” . Everyone likes problems with short statements. Right? Let’s have five positive numbers: X1,X2,X3,X4,X5. We can form 10 distinct pairs of these five numbers. Given the sum of each one of the pairs, you are asked to find out the original five numbers.
The first line will be the number of test cases T. Each test case is described in one line which contains 10 numbers, these are the sum of the two numbers in each pair. Notice that the input has no particular order, for example: the first number doesn’t have to be equal to {X1+ X2}. All numbers are positive integers below 100,000,000.
For each test case, print one line which contains the number of the test case, and the five numbers X1,X2,X3,X4,X5 in ascending order, see the samples and follow the output format. There always exists a unique solution.
2
15 9 7 15 6 12 13 16 21 14
12 18 13 10 17 20 21 15 16 14
Case 1: 2 4 5 10 11
Case 2: 4 6 8 9 12
#include <bits/stdc++.h>
using namespace std;
#define maxn 22
long long s[maxn], ans[maxn];
long long sum;
int main () {
//freopen ("in.txt", "r", stdin);
int kase = 0, t;
cin >> t;
while (t--) {
printf ("Case %d: ", ++kase);
sum = 0;
for (int i = 1; i <= 10; i++) {
cin >> s[i];
sum += s[i];
}
sort (s+1, s+1+10);
sum /= 4;
ans[3] = sum-s[1]-s[10];
ans[2] = sum-s[2]-s[10];
ans[4] = sum-s[1]-s[9];
ans[5] = s[10]-ans[4];
ans[1] = s[1]-ans[2];
for (int i = 1; i <= 5; i++) {
printf ("%lld%c", ans[i], i == 5 ? '\n' : ' ');
}
}
return 0;
}