Pagini recente » Cod sursa (job #2515366) | Cod sursa (job #683768) | Cod sursa (job #2777858) | Cod sursa (job #2374179) | Cod sursa (job #1846409)
#include <fstream>
#include <deque>
#include <utility>
#include <vector>
using namespace std;
ifstream fin("branza.in");
ofstream fout("branza.out");
deque < pair <int,int> > dq;
int n,p,t,i,c,x,cost;
int main()
{
fin>>n>>p>>t;
for(i=1;i<=n&&i<=t;i++)
{
fin>>c>>x;
if(!dq.empty()){
int q=dq.back().first;
int w=dq.back().second;}
while(!dq.empty()&&dq.back().first+p*(i-dq.back().second)>c)
{
dq.pop_back();
}
dq.push_back(make_pair(c,i));
int q=dq.front().first;
int w=dq.front().second;
cost+=(q+p*(i-w))*x;
}
for(i=t+1;i<=n;i++)
{
fin>>c>>x;
if(!dq.empty()){
int q=dq.back().first;
int w=dq.back().second;}
while(!dq.empty()&&dq.back().first+p*(i-dq.back().second)>c)
{
dq.pop_back();
}
dq.push_back(make_pair(c,i));
int q=dq.front().first;
int w=dq.front().second;
cost+=(q+p*(i-w))*x;
}
fout<<cost<<'\n';
return 0;
}