Cod sursa(job #2901055)

Utilizator CaptnBananaPetcu Tudor CaptnBanana Data 12 mai 2022 20:11:52
Problema Tribute Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("tribute.in");
ofstream g("tribute.out");

const int N = 5e4 + 1;
int n, dx, dy, dreptx, drepty, ans; // coltul stanga jos
int x[N], y[N], xs[N], ys[N];

int main(){
    f >> n >> dx >> dy;
    for(int i = 0; i < n; i++){
        f >> x[i] >> y[i];
        xs[i] = x[i];
        ys[i] = y[i];
    }

    f.close();

    sort(xs, xs + n);
    sort(ys, ys + n);

    dreptx = xs[n / 2] - dx;
    drepty = ys[n / 2];

    for(int i = 0; i < n; i++){
        if(x[i] > dreptx + dx || x[i] < dreptx)
            ans += min(abs(x[i] - dreptx), abs(x[i] - dreptx - dx));

        if(y[i] > drepty + dy || y[i] < drepty)
            ans += min(abs(y[i] - drepty), abs(y[i] - drepty - dy));
    }

    g << ans << '\n';
}