Pagini recente » Cod sursa (job #2768795) | Cod sursa (job #1082725) | Cod sursa (job #936892) | Cod sursa (job #1138028) | 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;
}