题目链接:http://poj.org/problem?id=2393
题意:每周生产酸奶的成本是C_i,生产的数量是Y_i,储存酸奶的成本是s,问最小的成本是多少?
解题思路:每生产完一周之后,就记录下该周生产的单价,到下一周时比较该周的生产单价和之前记录下的生产单价加上储存的费用,从而得出最小的生产价格。
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int64;
int main() {
int n, s;
while (scanf("%d %d", &n, &s) == 2) {
int64 ans = 0, t;
int c, y;
for (int i = 0; i < n; i++) {
scanf("%d %d", &c, &y);
if (i == 0) {
t = (int64)c;
} else {
t = min(t + s, (int64)c);
}
ans += t * y;
}
printf("%lld\n", ans);
}
return 0;
}