알고리즘/백준
2470. 두 용액
혬혬
2021. 10. 31. 01:19
728x90
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int main(void) {
freopen("inp.inp", "r", stdin);
freopen("out.out", "w", stdout);
int n;
cin >> n;
vector<int> list;
vector<int> answer(2);
for (int i = 0; i < n; i++) {
int box = 0;
cin >> box;
list.push_back(box);
}
sort(list.begin(), list.end());
int s = 0;
int e = n-1;
long long min = 2000000001;
while (s < e) {
long long sum = list[s] + list[e];
if (min >= abs(sum)) {
min = abs(sum);
answer[0] = list[s];
answer[1] = list[e];
if (sum == 0)
break;
}
if (sum < 0) s++;
else e--;
}
cout << answer[0] << " " << answer[1];
return 0;
}
https://www.acmicpc.net/problem/2470
728x90