This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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));
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));
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |