Pagini recente » Cod sursa (job #1302462) | Borderou de evaluare (job #322045) | Cod sursa (job #246017) | Cod sursa (job #2660110) | Cod sursa (job #2412005)
#include <fstream>
using namespace std;
ifstream f("branza.in");
ofstream g("branza.out");
const int Nmax = 100005;
int cant, cost[Nmax], best[Nmax];
long long int suma;
int n,s,t, last = -1, first;
int main(){
int i;
f >> n >> s >> t;
for(i = 1; i <= n ; i++){
f >> cost[i] >> cant;
if(best[first] == i - t - 1)
first++;
while(first <= last && cost[i] <= (cost[best[last]] + (i - best[last]) * s ))
last--;
best[++last] = i;
suma += cant * (cost[best[first]] + (i - best[first]) * s);
}
g << suma;
return 0;
}