Cod sursa(job #2580755)

Utilizator valentinchipuc123Valentin Chipuc valentinchipuc123 Data 14 martie 2020 04:07:58
Problema Carnati Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <bits/stdc++.h>

using namespace std;

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

int c, n, ans;
pair <int,int> v[2005];

int main()
{

    fin >> n >> c;

    for(int i = 1; i <= n; i++)
        fin >> v[i].first >> v[i].second;
    sort(v+1, v+1+n);
    for(int i = 1; i <= n; i++)
    {
        int x = v[i].second, t, p;
        t =0;
        p = -69696969;
        for(int j = 1; j <= n; j++)
        {
            if(v[j].second >= x)
            {
                if(p+x-(v[j].first-t)*c < x-c) p = x-c;
                else
                    p = p+x-(v[j].first-t)*c;
                t = v[j].first;
                ans = max(p, ans);

            }
        }
    }

    fout << ans;


    return 0;
}