Cod sursa(job #1385431)

Utilizator akaprosAna Kapros akapros Data 11 martie 2015 22:45:43
Problema Carnati Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<cstdio>
#include<cstring>
#include<algorithm>
#define Nmax 2005
using namespace std;
int n,m,i,j,c;
struct nod
{
    int p;
    int t;
}v[Nmax];
int cmp(const nod a,const nod b)
{
    if (a.t==b.t) return a.p>b.p;
    return a.t<b.t;
}
int sum,best,x;
int main()
{
    freopen("carnati.in","r",stdin);
    freopen("carnati.out","w",stdout);
    scanf("%d %d",&n,&c);
    for (i=1;i<=n;i++)
    scanf("%d %d",&v[i].t,&v[i].p);
    sort(v+1,v+n+1,cmp);
    for (i=1;i<=n;i++)
    {
        sum=0;
        for (j=1;j<=n;j++)
        {
            x=0;
            if (v[j].p>=v[i].p)
            x=v[i].p;
            if (sum<=0)
            sum=x-c;
            else sum+=x-(v[j].t-v[j-1].t)*c;
            if (sum>best)
            best=sum;
        }
    }
    printf("%d",best);
    return 0;
}