Pagini recente » Cod sursa (job #2739666) | Cod sursa (job #3206293) | Cod sursa (job #2447309) | Cod sursa (job #1827953) | Cod sursa (job #2887423)
#include <bits/stdc++.h>
using namespace std;
ifstream f("branza.in");
ofstream g("branza.out");
#define cin f
#define cout g
#define int long long
int n, s, t, ans = 0;
queue < pair < int, int > > costs;
int32_t main()
{
cin >> n >> s >> t;
for(int i = 1; i <= n; i ++)
{
int cost, cantitate;
cin >> cost >> cantitate;
if(! costs.empty())
if(cost < (costs.front().first + s * (i - costs.front().second)))
while(! costs.empty())
costs.pop();
costs.push(make_pair(cost, i));
ans += (costs.front().first + s * (i - costs.front().second)) * cantitate;
if(costs.front().second + t == i)
{
costs.pop();
queue < pair < int, int > > aux;
int mn = costs.front().first + s * (i - costs.front().second);
aux.push(make_pair(costs.front().first, costs.front().second));
costs.pop();
while(! costs.empty())
{
if(mn > costs.front().first + s * (i - costs.front().second))
while(! aux.empty())
aux.pop();
aux.push(make_pair(costs.front().first, costs.front().second));
}
while(! aux.empty())
{
costs.push(aux.front());
aux.pop();
}
}
}
cout << ans;
return 0;
}