傳送門:
code:
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
| typedef vector<pair<int, pii> >::iterator Iter;
inline bool operator!= (const pii &x, const pii &y){
return (x.X != y.X && x.X != y.Y && x.Y != y.X && x.Y != y.Y);
}
ll N, arr[1005], ans;
vector<pair<int, pii> > record;
void init(){
for(int i=0;i<N;i++) arr[i] = getint();
sort(arr, arr+N, greater<ll>());
record.clear();
ans = -INT_MAX;
}
inline bool cmp(const pair<int,pii> &a, const int& b){
return a.X < b;
}
inline bool succ(int x, int v) {
return record[x].X <= v;
}
void sol(){
pair<int, pii> piii;
int l, r;
for(int i=0;i<N;i++)for(int j=i+1;j<N;j++){
piii.X = arr[i] + arr[j];
piii.Y.X = i;
piii.Y.Y = j;
record.PB(piii);
}
sort(record.begin(), record.end());
for(int i=0;i<N;i++)for(int j=0;j<N;j++)if(i!=j){
l=0, r=record.size();
#define mid ((l+r)>>1)
while(r-l>1) succ(mid, arr[i]-arr[j]) ? l=mid : r=mid;
if(arr[i]-arr[j] == record[l].X && MP(i,j) != record[l].Y){
ans = arr[i];
return;
}
}
}
inline void prin(){
if(ans == -INT_MAX) puts("no solution");
else cout << ans << endl;
}
int main(){
while(cin >> N && N){
init();
sol();
prin();
}
} |
comments powered by