-
Notifications
You must be signed in to change notification settings - Fork 0
/
sumset.cpp
60 lines (50 loc) · 1.21 KB
/
sumset.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
60
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> pii;
bool t=false;
int solve(vector<int> arr,int n){
int d=-100000000;
for(int x=n-1;x>=0;x--){
for(int k=0;k<n;k++){
for(int i=k+1;i<n;i++){
for(int j=i+1;j<n;j++){
if(arr[i]!=arr[x] && arr[j]!=arr[x] && arr[x]!=arr[k]){
if(arr[x] == arr[i]+arr[j]+arr[k]){
d = max(d,arr[x]);
t = true;
return d;
}
}
}
}
}
}
return d;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int n;
while(cin>>n&&n){
vector<int> arr(n,0);
for(int i=0;i<n;i++)
cin>>arr[i];
sort(arr.begin(),arr.end());
t=false;
int d = solve(arr,n);
if(t)
cout<<d<<'\n';
else
cout<<"no solution\n";
}
return 0;
}