Cod sursa(job #2624807)

Utilizator dream3rDavid Pop dream3r Data 5 iunie 2020 14:01:29
Problema Branza Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
//#include "pch.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <deque>
#include <climits>
#define len 100005
using ll = long long int;
using namespace std;
fstream f("branza.in");
ofstream o("branza.out");
int n, cost, zile;
ll costa, cant;
vector<int>v(100005, 0);
deque<ll>coada;



int main()
{
	f >> n >> cost >> zile;
	for (size_t i = 1; i <= n; i++)
	{
		f >> v[i] >> cant;

		if (!coada.empty() && i - coada.front() > zile)
		{
			coada.pop_front();
		}

		while (!coada.empty() && (v[coada.front()] + (i - coada.front())*cost >= v[i]))
		{
			coada.pop_back();
		}
		coada.push_back(i);

		costa += cant * (v[coada.front()] + (i - coada.front())*cost);

	}
	o << costa;



}