#include <stdio.h>
#include <algorithm>
#include <string.h>

using namespace std;

int arr[100001], DP[100001];

int abs(int a) {
    return (a>0? a:-a);
}

int main() {

    int N, p1, p2, cet[3]={}; //용액의 값에 따라 pointer1, pointer2를 이동시키면서 적정값 찾기 =

    scanf("%d", &N);

    for(int i=1; i<=N; i++) {

        scanf("%d", &arr[i]);
    }

    sort(arr+1, arr+N+1);

    p1=1; p2=N;
    cet[1]=p1; cet[2]=p2;

    for(int i=1; ; i++) {

        if(p1>=p2) break;

        DP[i]=arr[p1]+arr[p2];

        if(abs(DP[i])<abs(arr[cet[1]]+arr[cet[2]])) {
            cet[1]=p1; cet[2]=p2;
        }

        if((arr[p1]+arr[p2])<0)
            p1++;
        else if((arr[p1]+arr[p2])==0)
            break;
        else
            p2--;

    }

    printf("%d %d", arr[cet[1]], arr[cet[2]]);
}

Embed on website

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