코딩테스트/백준

[골5] 2467 - 용액

ShovelingLife 2023. 9. 26. 10:50
#include <iostream>
#include <vector>
#include <cmath>

#define FAST_IO() \
{\
	ios::sync_with_stdio(false);\
	cin.tie(NULL); \
	cout.tie(NULL); \
}\

using namespace std;

int main()
{
	FAST_IO();
	int n;
	cin >> n ;
	vector<int> v(n);

	for (int i = 0; i < n; i++)
		cin >> v[i];

	int s = 0, e = n - 1, min = 2e9;
	pair<int, int> res;

	while (s < e)
	{
		int a = v[s], b = v[e];
		int val = abs(a + b);

		if (val < min)
		{
			min = val;
			res = { a, b };
		}
		if (a + b < 0)
			s++;

		else
			e--;
	}
	cout << res.first << ' ' << res.second;
	return 0;
}