Pagini recente » Cod sursa (job #786036) | Cod sursa (job #492808) | Cod sursa (job #2620745) | Cod sursa (job #619780) | Cod sursa (job #1362548)
#include<stdio.h>
#include<deque>
int cost[100001],cant[100001];
int main()
{
FILE *fin,*fout;
fin=fopen("branza.in","r");
fout=fopen("branza.out","w");
int n,s,t;
long long int costT=0;
fscanf(fin,"%d %d %d",&n,&s,&t);
std::deque<long long int> cm;
std::deque<long long int> pos;
for(int i=1;i<=n;i++)
{
fscanf(fin,"%d %d",&cost[i],&cant[i]);
while(!cm.empty()&&cant[i]*cost[i]<cm.back()*cant[i]+s*(i-pos.back())*cant[i])
{
pos.pop_back();
cm.pop_back();
}
while(i-pos.front()>t&&!pos.empty())
{
pos.pop_front();
cm.pop_front();
}
pos.push_back(i);
cm.push_back(cost[i]);
costT+=(cm.front()*cant[i]+s*cant[i]*(i-pos.front()));
}
fprintf(fout,"%lld",costT);
}