Pagini recente » Cod sursa (job #2825558) | Cod sursa (job #2463851) | Cod sursa (job #1046038) | Cod sursa (job #2418006) | Cod sursa (job #2888655)
#include <iostream>
#include <fstream>
#include <deque>
std::ifstream f("branza.in");
std::ofstream g("branza.out");
int N, S, T, c[100001], p[100001], cost=0;
std::deque<int>x;
int main()
{
int i;
f >> N >> S >> T;
for(i=1; i<=N; i++)
f >> c[i] >> p[i];
for(i=1; i<=N; i++)
{
while(x.empty()==0 && x.front() + T < i)
x.pop_front();
while(x.empty()==0 && c[x.back()]+S*(i - x.back()) > c[i])
x.pop_back();
x.push_back(i);
cost += p[i]*(c[x.front()]+(i-x.front())*S);
}
g<<cost;
}