Cod sursa(job #2405142)

Utilizator mihnea.anghelMihnea Anghel mihnea.anghel Data 13 aprilie 2019 23:25:40
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>
#include <deque>
#define val first
#define poz second

using namespace std;
ifstream f("branza.in");
ofstream g("branza.out");
long long n, pretdep, zilemax, p,u, cant, i, sol, v[100009], pret[100009] ;

int main()
{
	f >> n >> pretdep >> zilemax;
	p=1; u=0;
	for( i=1; i<=n; i++){
		f >> pret[i] >> cant;
		while ( p <= u && pret[v[u]] + pretdep * (i-v[u]) >= pret [i] ) 
			u--;
		
		v[++u]=i;
		if( v[p] == i-zilemax-1 ) p++;
		
		sol += cant * ( pret [ v[p] ] + pretdep * ( i - v[p] ) ) ;
	}
	g<<sol;
	return 0;
}