[Link] https://www.acmicpc.net/problem/2473
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
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <stack>
// #include <bits/stdc++.h>
using namespace std;
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i < n; i++)
#define fori(s, e) for(int i = s; i < e; i++)
#define ll long long
#define endl "\n"
#define nulls '\0'
#define dkdk " "
const int MAX = 5e5 + 1;
const int INF = 987654321;
int n;
ll min_val = 3e9+1;
int liq_arr[3];
vector<int> liq;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
liq.resize(n);
for0(i, n) cin >> liq[i];
sort(liq.begin(), liq.end());
ll ans = 1e10;
for(int i = 0; i < n; i++) {
int l = i + 1, r = n - 1;
int target = - (l + r);
while(l < r) {
ll v = (ll)liq[i] + liq[l] + liq[r];
if(abs(v) < abs(min_val)) {
min_val = v;
liq_arr[0] = liq[i], liq_arr[1] = liq[l], liq_arr[2] = liq[r];
}
if(v == 0) break;
if(v > 0) r--;
else l++;
}
}
for(int e : liq_arr) cout << e << " " ;
return 0;
}