Cod sursa(job #2719321)

Utilizator alessiamtr12Mitrica Alessia alessiamtr12 Data 9 martie 2021 19:28:36
Problema Carnati Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <fstream>
#include<algorithm>
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
int n,m,c,prof,dp[2005],maxx,minn;
struct om
{
    int t,p;
}v[2005];
bool cmp(om x, om y)
{
    return x.t<y.t||x.t==y.t&&x.p>y.p;
}
int main()
{
    fin>>n>>c;
    for(int i=1;i<=n;i++)
    {
        fin>>v[i].t>>v[i].p;
    }
    sort(v+1,v+n+1,cmp);
    int tmax=v[n].t;
    for(int i=1;i<=n;i++)
    {
        prof=v[i].p;
        for(int j=1;j<=n;j++)
            if(v[j].p>=prof)
                dp[v[j].t]+=prof;
          dp[0]-=c;
         for(int j=1;j<=tmax;j++)
            dp[j]+=dp[j-1]-c;
         minn=0;
         for(int j=1;j<=tmax;j++)
         {
             minn=min(minn,dp[j]);
             maxx=max(maxx,dp[j]-minn);
         }
         for(int j=0;j<=tmax;j++)
            dp[j]=0;
    }
    fout<<maxx;
    return 0;
}