Cod sursa(job #2445124)

Utilizator Ionut28Porumb Palincas Ionut Ionut28 Data 2 august 2019 16:20:46
Problema Heavy metal Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("heavymetal.in");
ofstream fout("heavymetal.out");
const int nmax = 100005;
long long dp[nmax];
int n, i;
long long a, b;
long long dif, s;
int main()
{
    fin >> n;
    for(i = 1; i <= n; ++i)
    {
        fin >> a >> b;
        dif = b - a;
        dp[i] = dif;
    }
    dp[n + 1] = 1e9+5;
    sort(dp + 1, dp + n + 1);
    for(i = n; i >= 1; i--)
    {
       if(dp[i] < dp[i + 1])
         s += dp[i];
    }
    fout << s;
    return 0;
}