Mai intai trebuie sa te autentifici.
Cod sursa(job #1753663)
| Utilizator | Data | 6 septembrie 2016 21:35:38 | |
|---|---|---|---|
| Problema | Branza | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.91 kb |
#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;
}
