Cod sursa(job #1458664)

Utilizator Alexa2001Alexa Tudose Alexa2001 Data 8 iulie 2015 11:39:01
Problema Branza Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream>
#define c first
#define z second
#include <queue>
using namespace std;

deque< pair<int,int> > st;
int cost,cant,i,n,s,t;
long long COST;
ifstream f("branza.in");
ofstream g("branza.out");
int main()
{
    f>>n>>s>>t;COST=0;
    for(i=1;i<=n;++i)
    {
       f>>cost>>cant;
       if(st.front().z==i-t) st.pop_front();
       while(!st.empty() && cost<1LL*(i-st.back().z)*s+st.back().c) st.pop_back();
       st.push_back({cost,i});
       COST+=1LL*cant*(1LL*(i-st.front().z)*s+st.front().c);
    }
    g<<COST<<'\n';
    return 0;
}