POJ 2393 Yogurt factory [Ad Hoc]

来源:互联网 发布:东华软件股份公司 待遇 编辑:程序博客网 时间:2024/06/08 12:47

POJ 2393 Yogurt factory

Description

N周,每周有一个酸奶价钱和要卖出的酸奶数,也可以存之前的酸奶来买,不过要付每周S的储存费,酸奶不会坏= =。问罪节省成功的弄法?

Algorithm

记录个最少价钱,每次和上一次比,然后看刷不刷新
注意

Note that the total might be too large for a 32-bit integer
要用long long

Code

#include <cstdio>#include <iostream>using namespace std;const int INF = 2e9;int main(){  int n, s;  scanf("%d%d", &n, &s);  int mins = INF;  long long ans = 0;  for (int i = 0; i < n; i++)  {    int c, y;    scanf("%d%d", &c, &y);    if (c < mins + s) mins = c; else mins += s;    ans += mins * y;  }  cout<<ans;  return 0;}
0 0
原创粉丝点击