-
Notifications
You must be signed in to change notification settings - Fork 0
/
10125 - Sumsets.cpp
59 lines (55 loc) · 1.02 KB
/
10125 - Sumsets.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
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
bool isvalid(int a, int b, int c, int d)
{
if(a == b || a == c || a == d) return false;
if(b == c || b == d) return false;
if(c == d) return false;
return true;
}
int main()
{
int n;
while(scanf("%d", &n), n)
{
int d, m = n;
set<int> s;
vector <int> v;
vector <pair <int, int> > vp;
bool found = false;
for(int i = 0; i < n; i++)
{
int a;
scanf("%d", &a);
s.insert(a);
v.push_back(a);
}
sort(v.begin(), v.end());
int len = v.size();
for(int i = 0; i < len-1; i++)
{
for(int j = i+1; j < len; j++)
{
if(v[i] != v[j])
vp.push_back(make_pair(v[i], v[j]));
}
}
int len2 = vp.size();
for(int i = len-1; i >= 0; i--)
{
for(int j = 0; j < len2; j++)
{
int c = v[i]-vp[j].first - vp[j].second;
if(isvalid(v[i], vp[j].first, vp[j].second, c) && s.find(c) != s.end())
{
printf("%d\n", v[i]);
found = true;
break;
}
}
if(found) break;
}
if(!found) puts("no solution");
}
return 0;
}