Cod sursa(job #1700011)

Utilizator sucureiSucureiRobert sucurei Data 9 mai 2016 09:04:08
Problema Branza Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 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=0LL;
    for(i=1;i<=n;++i)
    {
       f>>cost>>cant;
       if(st.front().z<i-t) st.pop_front();
       while(!st.empty() && cost<=(i-st.back().z)*s+st.back().c) st.pop_back();
       st.push_back({cost,i});
       COST=COST+1LL*cant*((i-st.front().z)*s+st.front().c);
    }
    g<<COST<<'\n';
    return 0;
}