Cod sursa(job #3312154)

Utilizator RuxandraPro12_Metehau Ruxandra Maria RuxandraPro12_ Data 26 septembrie 2025 15:45:12
Problema Tribute Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin ("tribute.in");
ofstream fout ("tribute.out");

int n, dx, dy;
pair <int, int> v[50005];
bool cmp (pair <int, int> a, pair <int, int> b) {
    if (a.first > b.first)
        return false;
    else if (a.first == b.first) {
        if (a.second > b.second)
            return false;
        return true;
    }
    return true;
}

int main() {
    fin >> n >> dx >> dy;
    for (int i = 1; i <= n; i++)
        fin >> v[i].first >> v[i].second;
    sort (v + 1, v + 1 + n, cmp);
    ///for (int i = 1; i <= n; i++)
        ///fout << v[i].first << " " << v[i].second << "\n";
    int i = 1, j = n, distanta = 0;
    while (i <= j) {
        if (v[j].first - v[i].first - dx > 0)
            distanta += v[j].first - v[i].first - dx;
        if (v[j].second - v[i].second - dy > 0)
            distanta += v[j].second - v[i].second - dy;
        i++;
        j--;
    }
    fout << distanta << "\n";
    return 0;
}