Pagini recente » Cod sursa (job #2136296) | Cod sursa (job #2352015) | Clasament tp4 | Cod sursa (job #94888) | Cod sursa (job #2889029)
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream fin("branza.in.txt");
ofstream fout("branza.out.txt");
int main()
{
deque < long long int > branza;
long long int suma = 0;
long long int n, s, t;
fin>>n>>s>>t;
long long int cost[n], cant[n];
for(long long int i = 0; i < n; i++)
fin>>cost[i]>>cant[i];
for(long long int i = 0; i < n; i++){
while(!branza.empty() && cost[i] <= cost[branza.back()] + s * (i-branza.back())){
branza.pop_back();
}
branza.push_back(i);
suma = suma + cant[i] * (cost[branza.front()] + s * (i - branza.front()));
if(i - branza.front() > t){
branza.pop_front();
}
}
fout<<suma;
}