Pagini recente » Cod sursa (job #2570880) | Cod sursa (job #165961) | Cod sursa (job #2377837) | Cod sursa (job #2364956) | Cod sursa (job #1753663)
#include <fstream>
#include <iostream>
#include <deque>
using namespace std;
ifstream in("branza.in");
ofstream out("branza.out");
deque<long long int> DQzi,DQcost;
int main()
{
int zile,taxa,stric;
long long int sol=0;
in>>zile>>taxa>>stric;
for(int i=1;i<=zile;i++)
{
int cost,cant;
in>>cost>>cant;
while(DQzi.empty()==0 && cost<=(i-DQzi.back())*taxa+DQcost.front())
{
DQzi.pop_back();
DQcost.pop_back();
} /// Elimin ce e mai prost decat ziua curenta
while(DQzi.empty()==0 && i-DQzi.front()>stric)
{
DQzi.pop_front();
DQcost.pop_front();
} /// Elimin ce e stricat
DQzi.push_back(i);
DQcost.push_back(cost);
/// Adaug in deque ziua curenta
sol=sol+cant*((i-DQzi.front())*taxa+DQcost.front());
}
out<<sol;
}