Submission #320748

#TimeUsernameProblemLanguageResultExecution timeMemory
320748egasBest Place (NOI17_bestplace)C++14
100 / 100
41 ms2184 KiB
#include <bits/stdc++.h> using namespace std; long long getManHat(long long x, vector<long long> &a) { long long res=0; for(long long i = 0 ; i < a.size() ; i++) { res+=abs(x-a[i]); } return res; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; vector<long long> X,Y; for(long long i = 0 ; i < n ; i++) { long long x; cin >> x; long long y; cin >> y; X.push_back(x); Y.push_back(y); } sort(X.begin(),X.end()); sort(Y.begin(),Y.end()); long long resx; if(n%2==0) { if(getManHat(X[X.size()/2],X)<getManHat(X[(X.size()/2)-1],X)) { resx=X[X.size()/2]; } else { resx=X[(X.size()/2)-1]; } } else { resx=X[X.size()/2]; } long long resy; if(n%2==0) { if(getManHat(Y[Y.size()/2],Y)<getManHat(Y[(Y.size()/2)-1],Y)) { resy=Y[Y.size()/2]; } else { resy=Y[(Y.size()/2)-1]; } } else { resy=Y[Y.size()/2]; } cout << resx << ' ' << resy << '\n'; return 0; }

Compilation message (stderr)

bestplace.cpp: In function 'long long int getManHat(long long int, std::vector<long long int>&)':
bestplace.cpp:9:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for(long long i = 0 ; i < a.size() ; i++) {
      |                           ~~^~~~~~~~~~
#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...