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;
typedef long long ll;
#define f(i,a,b) for(ll i = a; i < b; i++)
const int N = 1e5 + 5;
const ll inf = 2e18;
ll n, a[N], b[N], A[N], B[N], sa[N], sb[N];
int main(){
cin >> n;
f(i,1,n+1) {
cin >> a[i] >> b[i];
A[i] = a[i], B[i] = b[i];
}
ll ans = inf, x, y;
sort(A+1, A+n+1);
sort(B+1, B+n+1);
f(i,1,n+1){
sa[i] = sa[i-1] + A[i];
sb[i] = sb[i-1] + B[i];
}
/*
f(i,1,n+1){
f(j,1,n+1){
ll res = 0;
int l = upper_bound(A+1, A+n+2, a[i]) - A;
int r = upper_bound(B+1, B+n+2, b[j]) - B;
l--, r--;
res += a[i] * l - sa[l] + (sa[n] - sa[l]) - a[i] * (n - l);
res += b[j] * r - sb[r] + (sb[n] - sb[r]) - b[j] * (n - r);
if(res < ans){
x = a[i], y = b[j];
ans = res;
}
}
}
*/
ll le = n/2;
f(i,max(1LL,le-5),min(n+1, le+5)){
f(j,max(1LL,le-5), min(n+1, le+5)){
ll res = 0;
res += A[i] * i - sa[i] + (sa[n] - sa[i]) - A[i] * (n - i);
res += B[j] * j - sb[j] + (sb[n] - sb[j]) - B[j] * (n - j);
if(res < ans){
x = A[i], y = B[j];
ans = res;
}
}
}
cout << x << " " << y << "\n";
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... |