Pagini recente » Cod sursa (job #1548018) | Cod sursa (job #1847892) | Cod sursa (job #3253783) | Cod sursa (job #1901817) | Cod sursa (job #2887515)
#include <bits/stdc++.h>
using namespace std;
ifstream f("branza.in");
ofstream g("branza.out");
#define cin f
#define cout g
const int Max = 1e5 + 1;
long long n, s, t, ans;
pair < int, int > d[Max];
int front, back;
int cost_nou(pair < int, int > x, int i)
{
return x.first + (i - x.second) * s;
}
int 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(d[front], i))
front = 1, back = 0;
back ++;
d[back].first = cost, d[back].second = i;
ans += cost_nou(d[front], i) * cantitate;
if(d[front].second + t == i)
{
front ++;
for(int j = front + 1; j <= back; j ++)
if(cost_nou(d[j], i) < cost_nou(d[front], i))
front = j;
}
}
cout << ans;
return 0;
}