-
Notifications
You must be signed in to change notification settings - Fork 1
/
02473.cpp
47 lines (40 loc) · 925 Bytes
/
02473.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
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
void solve(void) {
int n;
cin >> n;
vector<long long> a(n);
for (int i=0; i<n; i++) cin >> a[i];
sort(a.begin(), a.end());
vector<pair<int, int> > v(n-2);
int idx = -1;
long long min_sum = 3e9;
for (int i=0; i<n-2; i++) {
int lo = i+1, hi = n-1;
long long sum = 3e9;
v[i] = make_pair(lo, hi);
while (lo < hi) {
if (abs(a[i]+a[lo]+a[hi]) < sum) {
sum = abs(a[i]+a[lo]+a[hi]);
v[i] = make_pair(lo, hi);
}
if (a[i]+a[lo]+a[hi] < 0) lo++;
else hi--;
}
if (sum < min_sum) {
min_sum = sum;
idx = i;
}
}
cout << a[idx] << " " << a[v[idx].first] << " " << a[v[idx].second];
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
solve();
return 0;
}