题目链接: POJ—2393 Yogurt factory
基础的贪心(难的我也不会),从第一周开始遍历,每过一周把之前的价格上涨S(相当于把存储的费用直接算到价格中),然后从之前的所有价格中选择一个最低价来生产本周的酸奶就ok了。
PS:记得用long long。。。
(话说酸奶不会放坏嘛。。。)
举个例子:
input
4 5
88 200
89 400
97 300
91 500
output
126900
第一周生产200,第二周生产700,第三周不生产,第四周生产500;
把存储的费用直接算到价格中就是这样:
/***********************************
Problem: 2393 User: ChenyangDu
Memory: 764K Time: 563MS
Language: G++ Result: Accepted
************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 10000+5;
int n,S,y[maxn],c[maxn];
long long ans;
void input(){
scanf("%d%d",&n,&S);
for(int i=1;i<=n;i++){
scanf("%d%d",&c[i],&y[i]);
}
}
int main(){
//freopen("in.txt","r",stdin);
input();
for(int i=1;i<=n;i++){
int cost = 0x7fffffff;
for(int j=1;j<i;j++){
c[j] += S;
cost = min(c[j],cost);
}
cost = min(cost,c[i]);
ans += cost * y[i];
}
cout<<ans<<endl;
fclose(stdin);
return 0;
}