← Back to List

7571번: 점 모으기 ↗

Solutions

C++14
418 B | 418 chars
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll N,M,Sx,Sy,D;
ll X[110000];
ll Y[110000];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> M;
    for(int x=0; x<M; x++) {
        cin >> X[x] >> Y[x];
    }
    sort(X,X+M);
    sort(Y,Y+M);

    for(int x=0; x<M; x++) {
        D += llabs(X[x] - X[M/2]) + llabs(Y[x] - Y[M/2]);
    }
    cout << D;
}