[poj2393] Yogurt factory

题意:

奶牛有n天销售酸奶,每天的成本为\(C_i\),销售数量为\(Y_i\),你可以在当天现做现卖,也可以用以前储备下来的酸奶,但是每单位每储备一天需要额外花费s元,求销售所有酸奶的最小代价。

题解:

贪心

对每天的单位成本取min即可。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;

int c[10010],y[10010];

int gi() {
  int x=0,o=1; char ch=getchar();
  while(ch!='-' && (ch<'0' || ch>'9')) ch=getchar();
  if(ch=='-') o=-1,ch=getchar();
  while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return o*x;
}

int main() {
  int n=gi(),s=gi(),mi=1<<30;
  ll ans=0;
  for(int i=1; i<=n; i++) {
    c[i]=gi(),y[i]=gi();
    mi=min(mi+s,c[i]);
    ans+=mi*y[i];
  }
  printf("%lld\n", ans);
  return 0;
}
posted @ 2017-10-13 23:02  HLX_Y  阅读(113)  评论(0编辑  收藏  举报