Pagini recente » Cod sursa (job #414784) | Cod sursa (job #2093918) | Cod sursa (job #3142662) | Cod sursa (job #343511) | Cod sursa (job #3289185)
#include <fstream>
#include <vector>
#include <deque>
using namespace std;
ifstream fin("branza.in");
ofstream fout("branza.out");
int N,S,T,x;
int main()
{
fin>>N>>S>>T;
vector<int>v(N);
deque<int>dq(N);
long long total=0;
for(int i=0; i<N; i++)
{
long long cost=0;
fin>>v[i]>>x;
while(!dq.empty() && v[dq.back()]>=v[i])
dq.pop_back();
dq.push_back(i);
if(dq.front()==i-T-1)
dq.pop_front();
cost=1LL*v[dq.front()]*x+S*(i-dq.front());
if(1LL*v[i]*x<=cost)
total+=cost;
else
total+=1LL*v[i]*x;
}
fout<<total;
return 0;
}