#include<bits/stdc++.h>
#define debu
using namespace std;
typedef long long LL;
const int maxn=1e3+50;
const LL INF=1e10;
int n;
set<LL> s;
LL a[maxn];
map<LL,map<LL,LL> > num;
int check(LL x,LL y)
{
LL tmp=x-y;
/*if(s.count(tmp))
{
cout<<x<<" "<<y<<" "<<tmp<<endl;
cout<<num[tmp][0]<<" "<<num[tmp][1]<<endl;
}*/
return (s.count(tmp)&&num[tmp][0]!=x&&num[tmp][1]!=x&&num[tmp][0]!=y&&num[tmp][1]!=y);
}
void solve()
{
for(int i=0; i<n; i++)
for(int j=i+1; j<n; j++)
{
LL sum=a[i]+a[j];
num[sum][0]=a[i];
num[sum][1]=a[j];
s.insert(sum);
}
LL ans=-INF;
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
{
if((i!=j)&&check(a[i],a[j]))
ans=max(ans,a[i]);
}
if(ans==-INF) printf("no solution\n");
else printf("%lld\n",ans);
}
int main()
{
#ifdef debug
freopen("in.in","r",stdin);
#endif // debug
while(scanf("%d",&n)==1&&n)
{
s.clear();
num.clear();
for(int i=0; i<n; i++)
scanf("%lld",&a[i]);
solve();
}
return 0;
}
题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1066
题解:中途相遇法。n^2枚举所有a+b的和,n^2枚举两数相减,map[x][0],map[x][1],表示对于和x,使用的数为map[x][0],map[x][1],set记录x是否出现过,若x已存在且两数未使用则更新答案。