自己翻译:
给出N周酸奶生产价格和销量,给出无限大仓库单位酸奶的存储价格S;在满足销量的前提下,找出最小的生产成本
思路:
找出每周的最小生产成本 = min(week[i].price, week[i-1].price+s),生产就行了
#include<iostream>
#include<cstdio>
#include<fstream>
#include<queue>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstring>
#define MAX 11000
#define INF 10000000
using namespace std;
struct sale{
int prc;
int num;
};
int main(){
int N, S;
long log ans = 0;
sale week[MAX];
cin >> N >> S;
//第一周价格不能改变
cin >> week[0].prc >> week[0].num;
//在输入时就确定最优价格
for(int i=1; i<N; i++){
cin >> week[i].prc >> week[i].num;
week[i].prc = min(week[i].prc, week[i-1].prc + S);
}
for(int i=0; i<N; i++)
ans += week[i].prc * week[i].num;
cout << ans << endl;
return 0;
}