Pagini recente » Cod sursa (job #2945772) | Cod sursa (job #2006935) | Cod sursa (job #2072484) | Cod sursa (job #2065037) | Cod sursa (job #2412009)
#include <fstream>
using namespace std;
ifstream f("branza.in");
ofstream g("branza.out");
typedef long long int ll;
const int Nmax = 100005;
ll cant, cost[Nmax], best[Nmax];
ll suma;
ll 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;
}