T1:牛奶供应
本题难度简单,主要考察贪心算法。第 \(i\) 天的牛奶成本价为 \(\min(c_i, minp+s)\),其中 \(minp\) 为前 \(i-1\) 天中牛奶的最低成本价
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
int main() {
int n, s;
cin >> n >> s;
ll c, a;
cin >> c >> a;
ll ans = c*a;
ll minp = c;
for (int i = 2; i <= n; ++i) {
cin >> c >> a;
minp = min(minp+s, c);
ans += minp*a;
}
cout << ans << '\n';
return 0;
}