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>
using namespace std;
using ll = long long;
vector<pair<int, int>> points;
ll find_dist(int x, int y) {
ll ans = 0;
for (int i = 0; i < (int)points.size(); i++) {
ans += abs(x-points[i].first)+abs(y-points[i].second);
}
return ans;
}
int main() {
int n;
cin >> n;
points.resize(n);
for (int i = 0; i < n; i++) {
cin >> points[i].first >> points[i].second;
}
int l = 0, r = 1e9;
int ansx = 0, ansy = 0;
while (l < r) {
int x = (l+r)/2;
int t = 1e9, b = 0;
ll dist1 = 1e15;
while (b < t) {
int y = (b+t)/2;
int d1 = find_dist(x, y);
int d2 = find_dist(x, y+1);
dist1 = min(d1, d2);
if (d1 < d2)
t = y;
else
b = y+1;
}
ansy = t;
ll dist2 = 1e15;
b = 0, t = 1e9;
while (b < t) {
int y = (b+t)/2;
int d1 = find_dist(x+1, y);
int d2 = find_dist(x+1, y+1);
dist2 = min(d1, d2);
if (d1 < d2)
t = y;
else
b = y+1;
}
if (dist1 < dist2)
r = x;
else {
l = x+1;
ansy = t;
}
}
cout << r << ' ' << ansy << '\n';
return 0;
}
Compilation message (stderr)
bestplace.cpp: In function 'int main()':
bestplace.cpp:24:9: warning: unused variable 'ansx' [-Wunused-variable]
24 | int ansx = 0, ansy = 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... |