#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int n;
long long x[100005];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> x[i];
    }
    int st=0,en=n-1;
    long long res=2e9;
    int a=0,b=0;
    while(st<en) {
        long long mix=x[st]+x[en];
        if(abs(res)>abs(mix))  {
            res=mix;
            a=st;
            b=en;
        }
        if(mix<0) st+=1;
        else en-=1;
    }
    cout << x[a] << ' ' << x[b];
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: