페이지

2141번: 우체국

https://www.acmicpc.net/problem/2141


#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
long long tot, s;
pair<intint> p[100000];
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d %d", &p[i].first, &p[i].second), tot += p[i].second;
    sort(p, p + n);
    for (int i = 0; i < n; i++) {
        s += p[i].second;
        if (s >= (tot + 1) / 2) {
            printf("%d", p[i].first);
            break;
        }
    }
    return 0;
}

댓글 없음 :

댓글 쓰기