Cod sursa(job #2900618)

Utilizator seburebu111Mustata Dumtru Sebastian seburebu111 Data 11 mai 2022 16:11:31
Problema Tribute Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

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

int dx, dy, n;
vector<int> x, y;

int main()
{
    in>>n>>dx>>dy;
    int a, b;
    for(int i=0; i<n; i++)
    {
        in>>a>>b;
        x.push_back(a);
        y.push_back(b);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    int dr=n-1, st=0, rez=0;
    while(x[dr]-x[st]>dx){
        rez+=x[dr--]-x[st++]-dx;
    }
    dr=n-1, st=0;
    while(y[dr]-y[st]>dy){
        rez+=y[dr--]-y[st++]-dy;
    }
    out<<rez;
    return 0;
}