-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10655-Sumsets.cpp
46 lines (37 loc) · 1.03 KB
/
10655-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
#include <bits/stdc++.h>
using namespace std;
int find(vector<long long>& nums){
for(int d = nums.size()-1; d>0; d--){
for(int i = 0; i<nums.size()-3; i++){
for(int j = i+1; j<nums.size()-2; j++){
for(int k = j+1; k<nums.size()-1; k++){
// avoid duplicate
if(nums[i]+nums[j]+nums[k] == nums[d] && i!=j && j!=k && k!=d)
return nums[d];
}
}
}
}
return INT_MAX;
}
int main(){
int num;
while(cin >> num){
if(num == 0)
break;
else{
vector<long long> nums(num);
for(int i= 0; i<num; i++){
cin >> nums[i];
}
sort(nums.begin(), nums.end());
long long res = find(nums);
if(res == INT_MAX){
cout << "no solution" << endl;
}
else{
cout << res << endl;
}
}
}
}