Cod sursa(job #2887423)

Utilizator NFJJuniorIancu Ivasciuc NFJJunior Data 9 aprilie 2022 16:38:50
Problema Branza Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.16 kb
#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;
}