# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
949181 | vjudge1 | Best Place (NOI17_bestplace) | C++17 | 32 ms | 2136 KiB |
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 pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)v.size()
const int INF = 1e18;
const int mod = 998244353;
const int N = 1e5+5;
void solve(){
int n; cin >> n;
vector<int> x(n), y(n);
for(int i = 0; i < n; i++){
cin >> x[i] >> y[i];
}
int l = 0, r = 1e9;
int xans = 0;
while(l <= r){
int m1 = l + (r - l) / 3;
int m2 = r - (r - l) / 3;
int res1 = 0, res2 = 0;
for(int i = 0; i < n; i++){
res1 += abs(m1 - x[i]);
res2 += abs(m2 - x[i]);
}
if(res1 < res2){
r = m2 - 1;
xans = m1;
}else{
l = m1 + 1;
xans = m2;
}
}
l = 0;
r = 1e9;
int yans = 0;
while(l <= r){
int m1 = l + (r - l) / 3;
int m2 = r - (r - l) / 3;
int res1 = 0, res2 = 0;
for(int i = 0; i < n; i++){
res1 += abs(m1 - y[i]);
res2 += abs(m2 - y[i]);
}
if(res1 < res2){
r = m2 - 1;
yans = m1;
}else{
l = m1 + 1;
yans = m2;
}
}
cout << xans << ' ' << yans;
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
}
Compilation message (stderr)
# | 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... |