Cod sursa(job #1990370)

Utilizator Moise_AndreiMoise Andrei Moise_Andrei Data 11 iunie 2017 16:37:25
Problema Tribute Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <algorithm>
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("tribute.in");
ofstream out("tribute.out");
int v[50001], c[50001];
int main()
{
    int n, a, b;
    in >> n >> a >> b;
    for(int i = 1; i <= n; i ++)
        in >> v[i] >> c[i];
    sort(v + 1, v + n + 1);
    sort(c + 1, c + n + 1);
    int s = 0;
    for(int i = 1; i <= n / 2; ++i)
    {
        s += max(v[n - i + 1] - v[i] - a, 0);
        s += max(c[n - i + 1] - c[i] - b, 0);
    }
    out << s;
    return 0;
}