Cod sursa(job #1493184)

Utilizator pepsiM4A1Ozturk Arif pepsiM4A1 Data 28 septembrie 2015 20:32:25
Problema Branza Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <cstdio>
#define DIM 10000
char buff[DIM];
int c[100023],poz=0,p[100023],n,s,t;
long long dyn[100023];
void next()
{
    ++poz;
    if(poz>=DIM)
    {
        poz=0;
        fread(buff,1,DIM,stdin);
    }
}
int citeste()
{
    while((!('0'<=buff[poz]&&buff[poz]<='9')))
    {
        next();
    }
    int nr=0;
    while('0'<=buff[poz]&&buff[poz]<='9')
    {
        nr*=10;
        nr+=(buff[poz]-'0');
        next();
    }
    return nr;
}
int main()
{
    freopen ("branza.in","r",stdin);
    freopen ("branza.out","w",stdout);
    fread(buff,1,DIM,stdin);
    n=citeste();
    s=citeste();
    t=citeste();
    for(int i=1;i<=n;i++)
    {
        c[i]=citeste();
        p[i]=citeste();
    }
    for(int i=1;i<=n;i++)
    {
        dyn[i]=1000000000000;
        for(int j=i;i-j<=t&&j>0;j--)
        {
            if(dyn[i]>c[j]+(i-j)*s) dyn[i]=c[j]+(i-j)*s;
        }
    }
    long long sum=0;
    for(int i=1;i<=n;i++) sum+=(dyn[i]*p[i]);
    printf("%lld\n",sum);
}