Cod sursa(job #2904845)

Utilizator dobreraduDobre Radu Fabian dobreradu Data 18 mai 2022 10:18:59
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <deque>
#include <fstream>

using namespace std;

ifstream fin("branza.in");
ofstream fout("branza.out");

int main()
{
	long long N, T, S, pret, cantitate;
	fin >> N >> S >> T;
	deque<pair<long long, long long>>deck;
	long long suma = 0;
	for (int i = 1; i <= N; ++i)
	{
		fin >> pret >> cantitate;
		while (!deck.empty() && deck.front().second + T < i)
		{
			deck.pop_front();
		}
		while (!deck.empty() && deck.back().first + (i - deck.back().second) * S > pret)
			deck.pop_back();

		deck.push_back(make_pair(pret, i));

		suma += (deck.front().first + (i - deck.front().second) * S) * cantitate;
			//cout << (deck.front().first + (i - deck.front().second) * S) * cantitate << endl;

	}
	fout << suma;
}