forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10125.cpp
55 lines (52 loc) · 845 Bytes
/
10125.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
int find(vector<int> &set)
{
for (int d = set.size() - 1; d >= 0; --d) // find the largest d
{
for (int a = 0; a < set.size(); ++a)
{
for (int b = a + 1; b < set.size(); ++b)
{
for (int c = b + 1; c < set.size(); ++c)
{
if ((set[d] == set[a] + set[b] + set[c]) &&
a != d && b != d && c != d)
{
return set[d];
}
}
}
}
}
return INT_MAX;
}
int main()
{
int numElement;
while (cin >> numElement)
{
if (numElement == 0)
{
break;
}
/* input */
vector<int> set(numElement);
for (int i = 0; i < numElement; ++i)
{
cin >> set[i];
}
sort(set.begin(), set.end());
/* find d = a + b + c */
int d = find(set);
if (d == INT_MAX)
{
cout << "no solution\n";
}
else
{
cout << d << "\n";
}
}
return 0;
}