Submission #1059800

#TimeUsernameProblemLanguageResultExecution timeMemory
1059800vjudge1Best Place (NOI17_bestplace)C++17
100 / 100
27 ms5492 KiB
/**
 *                       \`*-.
 *                        )  _`-.
 *                       .  : `. .
 *                       : _   '  \
 *                       ; *` _.   `*-._
 *                       `-.-'          `-.
 *                         ;       `       `.
 *                         :.       .        \
 *                         . \  .   :   .-'   .
 *                         '  `+.;  ;  '      :
 *                         :  '  |    ;       ;-.
 *                         ; '   : :`-:     _.`* ;
 *          [VĐ]        .*' /  .*' ; .*`- +'  `*'
 *                      `*-*   `*-*  `*-*'
**/
/** HELLO WOLRD**/
#include <bits/stdc++.h>

#define NAME "main"
#define data DANG
#define ii pair<int64_t , int64_t>
#define fi first
#define se second

using namespace std;

const int64_t INF64 = 0x3f3f3f3f3f3f3f3f;
const int INF32 = 0x3f3f3f3f;
const int N = 1e5;

int n;
int64_t x[N + 2] , y[N + 2] , a[N + 2] , b[N + 2];
int64_t sum = INF64 , res1 , res2;

void init(){
    cin >> n;

    for(int i = 1 ; i <= n ; i++)
        cin >> x[i] >> y[i];
}

void solve(){
    sort(x + 1 , x + n + 1);
    sort(y + 1 , y + n + 1);

    for(int i = 1 ; i <= n ; i++)
        a[i] = x[i] + a[i - 1];

    for(int i =1  ; i <= n ; i++)
        b[i] = y[i] + b[i - 1];

    sum = INF64;
    for(int i = 1 ; i <= n ; i++){
        int64_t tmp = (a[n] - a[i] - x[i] * (n - i)) + (x[i] * (i - 1) - a[i - 1]);
        if(tmp < sum){
            sum = tmp;
            res1 = x[i];
        }
    }

    cout << res1 << " ";

    sum = INF64;
    for(int i = 1 ; i <= n ; i++){
        int64_t tmp = (b[n] - b[i] - y[i] * (n - i)) + (y[i] * (i - 1) - b[i - 1]);
        if(tmp < sum){
            sum = tmp;
            res2 = y[i];
        }
    }

    cout << res2;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
  
    init();
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...