Cod sursa(job #1322718)

Utilizator pepsiM4A1Ozturk Arif pepsiM4A1 Data 20 ianuarie 2015 12:19:54
Problema Carnati Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <stdio.h>
int n,c;
int a[1501],cost[1501],set[2001];
int main()
{
    freopen ("carnati.in","r",stdin);
    freopen ("carnati.out","w",stdout);
    scanf("%d%d",&n,&c);
    int p1,t;
    for(int i=1;i<=n;i++)
    {
            scanf("%d%d",&p1,&t);
            set[i]=t;
            a[p1]+=t;
    }
    int maxim=0,v,mpos;
    for(int val=1;val<=n;val++)
    {
            for(int i=1;i<=1500;i++)
            {
                            if(a[i]>=set[val])
                            {
                                              if(cost[i-1]+set[val]>=0) cost[i]=cost[i-1]+set[val];
                                              else cost[i]=0;
                            }
                            else cost[i]=cost[i-1];
                            cost[i]-=13;
                            if(cost[i]<0) cost[i]=0;
            }
            for(int i=1;i<=1500;i++)
            {
                            if(maxim<cost[i]) 
                            {
                                              mpos=i;
                                              maxim=cost[i];
                            }
                           // cost[i]=0;
            }
    }
    printf("%d\n",maxim);
}