Submission #892818

#TimeUsernameProblemLanguageResultExecution timeMemory
892818votranngocvyBest Place (NOI17_bestplace)C++14
64 / 100
24 ms3728 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
const int N = 1e5 + 5;
int n;
pii a[N];

namespace sub3 {
    bool check_condition() {
        for (int i = 1; i <= n; i++)
            if (a[i].se != 0) return false;
        return true;
    }
    void solve() {
        sort(a + 1,a + n + 1);
        int mid = (n + 1) / 2;
        cout << a[mid].fi << " " << a[mid].se << "\n";
    }
}

namespace sub4 {
    const int inf = 0x3f3f3f3f3f3f3f3f;
    bool check_condition() {
        if (n > 100) return false;
        for (int i = 1; i <= n; i++)
            if (a[i].fi > 100 || a[i].se > 100) return false;
        return true;
    }
    void solve() {
        int ans = inf,x = -1,y = -1;
        for (int i = 0; i <= 100; i++)
            for (int j = 0; j <= 100; j++) {
                int res = 0;
                for (int k = 1; k <= n; k++)
                    res += abs(i - a[k].fi) + abs(j - a[k].se);
                if (res < ans) ans = res,x = i,y = j;
            }
        cout << x << " " << y << "\n";
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i].fi >> a[i].se;
    if (n == 2) cout << a[1].fi << " " << a[1].se << "\n";
    else if (sub3::check_condition()) sub3::solve();
    else if (sub4::check_condition()) sub4::solve();
}
#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...