이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define f(i,j,n) for(ll i = j; i < n; ++i)
#define fr(i,j,n) for(ll i = j; i >= n; --i)
#define ff first
#define ss second
#define sz(v) (int) v.size()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> ii;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long double ld;
const int N = 1e5 + 20;
const int M = 2e3 + 20;
const ll inf = 1e18;
ll n,x[N],y[N],pr[N],su[N];
ll axe(vll v){
sort(v.begin(),v.end());
f(i,0,n) pr[i] = su[i];
ll ct = 1;
pr[0] = 0;
f(i,1,n){
pr[i] = pr[i-1] + abs(v[i]-v[i-1])*ct, ct++;
// cout << pr[i] << endl;
}
su[n-1] = 0, ct = 1;
fr(i,n-2,0){
su[i] = su[i+1] + abs(v[i+1]-v[i])*ct, ct++;
// cout << su[i] << endl;
}
ll mn = inf,id = 0;
f(i,0,n){
// cout << pr[i] << " " << su[i] << endl;
if(pr[i]+su[i] < mn) mn = pr[i] + su[i], id = i;
}
return v[id];
}
void solve(){
cin >> n;
f(i,1,n+1) cin >> x[i] >> y[i];
vll v = {};
pll ans = {0,0};
f(i,1,n+1) v.push_back(x[i]);
ans.ff = axe(v);
v.clear();
f(i,1,n+1) v.push_back(y[i]);
ans.ss = axe(v);
cout << ans.ff << " " << ans.ss << endl;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tc = 1;
// cin >> tc;
while(tc--) solve();
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... |