Cod sursa(job #3324275)

Utilizator veronica_stanciuStanciu Veronica veronica_stanciu Data 21 noiembrie 2025 21:32:27
Problema Carnati Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
#include <algorithm>
using namespace std;

ifstream cin("carnati.in");
ofstream cout("carnati.out");

int t[2001], p[2001], psr[2001], v[2001];

int main(){
    int n, c, i, j, pret, tmax=-1, profitmax=0;
    cin>>n>>c;
    for(i=1; i<=n; i++){
        cin>>t[i]>>p[i];
        if (tmax<t[i])
            tmax=t[i];
        psr[i]=p[i];
    }
    sort(psr+1, psr+1+n);
    for (i=1; i<=n; i++) {
        pret=psr[i];
        for (j=1; j<=tmax; j++)
            v[j]=-c;
        for (j=1; j<=n; j++)
            if (p[j]>=pret)
                v[t[j]]+=pret;
        int s=0, smax=0;
        for (j=1; j<=tmax; j++) {
            s+=v[j];
            if (smax<s)
                smax=s;
            if (s<0)
                s=0;
        }
        if (smax>profitmax)
            profitmax=smax;
    }
    cout<<profitmax;
    return 0;
}