Cod sursa(job #2468000)

Utilizator Asgari_ArminArmin Asgari Asgari_Armin Data 5 octombrie 2019 11:32:04
Problema Tribute Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
#include <algorithm>
using namespace std;

ifstream fin( "tribute.in" );
ofstream fout( "tribute.out" );
const int NMAX = 50000;
int x[NMAX + 1], y[NMAX + 1];

int main() {
    int n, st, dr, sol, i;
    fin >> n >> st >> dr;
    for( i = 1; i <= n; ++i )
      fin >> x[i] >> y[i];
    sort( x + 1, x + n + 1 );
    sort( y + 1, y + n + 1 );
    sol = 0;
    for( i = 1; i <= n; ++i ){
      sol += max(0, x[i + 1] - x[n - i] - st); //subsecventa de suma maxima
      sol += max(0, y[i + 1] - y[n - i] - dr);
    }
    fout << sol;
    return 0;
}