Pagini recente » Cod sursa (job #2493176) | Cod sursa (job #2932084) | Cod sursa (job #1889568) | Cod sursa (job #2496703) | Cod sursa (job #1362541)
#include<stdio.h>
#include<deque>
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;
int cost[n],cant[n];
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]);
if(pos.front()==i)
{
costT+=(cm.front()*cant[i]);
}
else
{
costT+=(cm.front()*cant[i]+s*cant[i]*(i-pos.front()));
}
}
fprintf(fout,"%lld",costT);
}