제출 #482699

#제출 시각아이디문제언어결과실행 시간메모리
482699Sneha_codesBest Place (NOI17_bestplace)C++14
36 / 100
87 ms4940 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int n;
    cin >> n;
    int x[n], y[n], a[n], b[n];
    for (int i = 0; i < n; i++) {
        int u, v;
        cin >> u >> v;
        x[i] = u;
        y[i] = v;
    }
    sort(x, x + n);
    sort(y, y + n);
    int px[n], py[n];
    px[0] = x[0];
    py[0] = y[0];
    for (int i = 0; i < n; i++) {
        px[i] = px[i - 1] + x[i];
        py[i] = py[i - 1] + y[i];
    }
    for (int i = 0; i < n; i++)
        a[i] = (x[i] * i) - (i > 0 ? px[i - 1] : 0) + (px[n - 1] - px[i]) - (x[i] * (n - i -1));
    for (int i = 0; i < n; i++)
        b[i] = (y[i] * i) - (i > 0 ? py[i - 1] : 0) + (py[n - 1] - py[i]) - (y[i] * (n - i-1));
    int X = 0, Y = 0,m1 = 1000000005, m2 = 1000000005;
    for (int i = 0; i < n; i++) {
        if (m1 > a[i]) {
            m1 = a[i];
            X = x[i];
        }
    }
    for (int i = 0; i < n; i++) {
        if (m2 > b[i]) {
            m2 = b[i];
            Y = y[i];
        }
    }
    cout << X << " " << Y << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...