Pagini recente » Cod sursa (job #3326933) | Diferente pentru problema/bt intre reviziile 5 si 6 | Cod sursa (job #3329400) | Cod sursa (job #3322406) | Cod sursa (job #3308639)
#include <bits/stdc++.h>
using namespace std;
ifstream in("branza.in");
ofstream out("branza.out");
int main()
{
int n,s,t;
in>>n>>s>>t;
unsigned long long CM=0;
deque<pair<int, int>> minime;
for(int i=0; i<n; i++)
{
int c,p;
in>>c>>p;
while(!minime.empty() && (minime.back().second)+(i-minime.back().first)*s>=c)
minime.pop_back();
pair<int, int> cost;
cost.first=i; cost.second=c;
minime.push_back(cost);
if(minime.front().first<i-t)
minime.pop_front();
CM+=(unsigned long long)(minime.front().second+(i-minime.front().first)*s)*p;
}
out<<CM;
return 0;
}