# MorsLin 的博客

### 题解 UVA10125 【Sumsets】

posted on 2019-01-20 11:19:26 | under 题解 |

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <unordered_map>
#define LL long long
using namespace std;
int k = 0, f = 1; char c = getchar();
while(c < '0' || c > '9'){
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9')
k = k*10+c-48, c=getchar();
return k*f;
}
struct zzz {
int p1, p2; bool x;
};
unordered_map <LL,zzz> q;
LL a[1010];
void solve() {
LL n = read(), ans = -0x7fffffff; q.clear();
if(!n) exit(0);
for(int i = 1; i <= n; ++i) a[i] = read();
sort(a+1, a+n+1);
for(int i = 1; i <= n; ++i)
for(int j = 1; j < i; ++j)
q[a[i]+a[j]].x = 1, q[a[i]+a[j]].p1=i, q[a[i]+a[j]].p2=j;

for(int i = 1; i <= n; ++i)
for(int j = 1; j < i; ++j)
if(q[a[i]-a[j]].x && q[a[i]-a[j]].p1 != i && q[a[i]-a[j]].p2 != j && q[a[i]-a[j]].p1 != j && q[a[i]-a[j]].p2 != i)
ans = max(ans, a[i]);  //a,b,c,d要为不同元素

if(ans!=-0x7fffffff) printf("%d\n",ans);
else printf("no solution\n");
}
int main() {
while(1) solve();
return 0;
}