Cod sursa(job #1493223)

Utilizator pepsiM4A1Ozturk Arif pepsiM4A1 Data 28 septembrie 2015 21:17:13
Problema Branza Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <cstdio>
#include <deque>
#define DIM 10000
char buff[DIM];
int c[100023],poz=0,p[100023],n,s,t;
int st=1,dr=0,deq[100023];
struct str
{
    int val;
    int pos;
}dq[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();
    long long sum=0;
    for(int i=1;i<=n;i++)
    {
        c[i]=citeste();
        p[i]=citeste();
        while(dr>=st&&c[i]<=c[deq[dr]]+s*(i-deq[dr])) dr--;
        dr++;
        deq[dr]=i;
        sum+=(c[deq[st]]+s*(i-deq[st]))*p[i];
    }
    printf("%lld\n",sum);
}