Cod sursa(job #2887533)

Utilizator NFJJuniorIancu Ivasciuc NFJJunior Data 9 aprilie 2022 19:27:02
Problema Branza Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 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
const int Max = 1e5 + 1;

int n, s, t, ans;
int d[Max], front, back;

int cost_nou(int poz, int i)
{
	return d[poz] + (i - poz) * s;
}
int32_t main()
{
	cin >> n >> s >> t;
	front = 1, back = 0;
	for(int i = 1; i <= n; i ++)
	{
		int cost, cantitate; 
		cin >> cost >> cantitate;
		if(front <= back)
			if(cost < cost_nou(front, i))
				front = back + 1;
		back ++;
		d[back] = cost;
		ans += cost_nou(front, i) * cantitate;
		if(front + t == i)
		{
			front ++;
			for(int j = front + 1; j <= back; j ++)
				if(cost_nou(j, i) < cost_nou(front, i))
					front = j;
		}
	}
	cout << ans;
	return 0;
}