Cod sursa(job #3353722)

Utilizator GabrielaBellaMircea Gabriela GabrielaBella Data 10 mai 2026 16:57:54
Problema Tribute Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <iostream>
#include <fstream>
#include <cstdio>
#include <climits>
#include <algorithm>

using namespace std;

int vl[50005];
int vc[50005];
int v[500][500];

int main()
{
    freopen("tribute.in", "r", stdin);
    freopen("tribute.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, dx, dy;
    cin >> n >> dx >> dy;
    for (int i=1; i<=n; i++) {
        cin >> vl[i] >> vc[i];
    }

    int ok;
    if (n%2==0) ok=n/2;
    else if (n%2==1) ok=(n+1)/2;
    nth_element(vl+1, vl+ok, vl+n+1);
    nth_element(vc+1, vc+ok, vc+n+1);

    //cout << vl[ok] << " " << vc[ok];

    long long suma=0;

    for (int i=1; i<=n; i++) {
        long long diff=LLONG_MAX, ver;
        int dif1, dif2;

        dif1=abs(vl[ok]-vl[i]);
        dif2=abs(vc[ok]-vc[i]);
        if (dif1+dif2<diff) diff=dif1+dif2;

        dif1=abs(vl[ok]-dx-vl[i]);
        dif2=abs(vc[ok]-vc[i]);
        if (dif1+dif2<diff) diff=dif1+dif2;

        dif1=abs(vl[ok]-dx-vl[i]);
        dif2=abs(vc[ok]+dy-vc[i]);
        if (dif1+dif2<diff) diff=dif1+dif2;

        dif1=abs(vl[ok]-vl[i]);
        dif2=abs(vc[ok]+dy-vc[i]);
        if (dif1+dif2<diff) diff=dif1+dif2;

        //cout << diff << " -> " << vl[i] << " " << vc[i] << endl;

        suma+=diff;
    }
    cout << suma;
    return 0;
}