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
#define pb push_back
#define S second
#define F first
const int N = 1e5 + 10;
const int inf = 2e9;
using namespace std;
int x[N],y[N],n;
int dist(int x1,int y1,int x2,int y2) {
return abs(x1 - x2) + abs(y1 - y2);
}
int solve(int X,int Y) {
int res = 0;
for(int i = 1; i <= n; i++) res += abs(x[i] - X) + abs(y[i] - Y);
return res;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
int smX = 0,smY = 0;
for(int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
smX += x[i];
smY += y[i];
}
int Q1 = smX / n,Q2 = (smX + n - 1) / n,W1 = smY / n,W2 = (smY + n - 1) / n;
int res = solve(Q1,W1);
res = min(res,solve(Q1,W2));
res = min(res,solve(Q2,W1));
res = min(res,solve(Q2,W2));
int rezX,rezY;
if(res == solve(Q1,W1)) {
rezX = Q1;
rezY = W1;
}else if(res == solve(Q1,W2)) {
rezX = Q1;
rezY = W2;
}else if(res == solve(Q2,W1)) {
rezX = Q2;
rezY = W1;
}else if(res == solve(Q2,W2)) {
rezX = Q2;
rezY = W2;
}
cout << rezX << " " << rezY;
return 0;
}
# | 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... |