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;
#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 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... |