Description

The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10,000) weeks, the price of milk and labor will fluctuate weekly such that it will cost the company C_i (1 <= C_i <= 5,000) cents to produce one unit of yogurt in week i. Yucky's factory, being well-designed, can produce arbitrarily many units of yogurt each week.

Yucky Yogurt owns a warehouse that can store unused yogurt at a constant fee of S (1 <= S <= 100) cents per unit of yogurt per week. Fortuitously, yogurt does not spoil. Yucky Yogurt's warehouse is enormous, so it can hold arbitrarily many units of yogurt.

Yucky wants to find a way to make weekly deliveries of Y_i (0 <= Y_i <= 10,000) units of yogurt to its clientele (Y_i is the delivery quantity in week i). Help Yucky minimize its costs over the entire N-week period. Yogurt produced in week i, as well as any yogurt already in storage, can be used to meet Yucky's demand for that week.

Input

* Line 1: Two space-separated integers, N and S.

* Lines 2..N+1: Line i+1 contains two space-separated integers: C_i and Y_i.

Output

* Line 1: Line 1 contains a single integer: the minimum total cost to satisfy the yogurt schedule. Note that the total might be too large for a 32-bit integer.

Sample Input

4 5
88 200
89 400
97 300
91 500

Sample Output

126900

Hint

OUTPUT DETAILS: 
In week 1, produce 200 units of yogurt and deliver all of it. In week 2, produce 700 units: deliver 400 units while storing 300 units. In week 3, deliver the 300 units that were stored. In week 4, produce and deliver 500 units. 
 
 
题目意思:由于市场原因牛奶的生产价格会有所波动,要求在将来的n周里,该公司拥有一个足够大的仓库储存制好的牛奶,每个单位的牛奶每周储存

 所需的费用为s,现给出将来n周生产每单位牛奶的价格及客户所需的数量(即提前知道了下面几周的牛奶价格和客户需求!!!),求出该公司将来n周内所要支付的最小生产值。
 
解题思路:这是一道贪心题,贪心策略,每一个周只需要和下一个周对比,每一次更新下一个相邻的周,因为若下一个周被更新了,那么下一个周可以用来更新剩下的周,所以每一个周只需要对下一个周负责就可以了,可以看成一种带有传递性的比较。
 
上代码:

 #include<stdio.h>
struct Yogurt
{
int c;
int y;
};
int main()
{
int n,s,i;
long long ans;
struct Yogurt a[];
a[].c=;
while(scanf("%d%d",&n,&s)!=EOF)
{
for(i=; i<=n; i++)
{
scanf("%d%d",&a[i].c,&a[i].y);
}
for(i=; i<=n; i++)
{
if(a[i].c<a[i-].c+s)
a[i].c=a[i].c;
else
a[i].c=a[i-].c+s;
}
ans=;
for(i=; i<=n; i++)
{
ans=ans+a[i].c*a[i].y;
}
printf("%lld\n",ans);
}
return ;
}

Yogurt factory的更多相关文章

  1. poj 2393 Yogurt factory

    http://poj.org/problem?id=2393 Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  2. BZOJ1680: [Usaco2005 Mar]Yogurt factory

    1680: [Usaco2005 Mar]Yogurt factory Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 106  Solved: 74[Su ...

  3. Yogurt factory(POJ 2393 贪心 or DP)

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8205   Accepted: 4197 De ...

  4. 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂

    1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 119  Solved:  ...

  5. POJ 2393 Yogurt factory 贪心

    Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...

  6. C - Yogurt factory

    The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 &l ...

  7. 【BZOJ】1680: [Usaco2005 Mar]Yogurt factory(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1680 看不懂英文.. 题意是有n天,第i天生产的费用是c[i],要生产y[i]个产品,可以用当天的也 ...

  8. POJ2393 Yogurt factory 【贪心】

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6821   Accepted: 3488 De ...

  9. BZOJ 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 贪心 + 问题转化

    Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...

随机推荐

  1. throws、throw和try catch

    在学习代理模式的时候,编写动态生成代理类.java文件时,用try{}catch(){}捕获异常发现catch(Exception e)报错,得换成catch(Throwable e),然后又查了查两 ...

  2. RHS 和 LHS

    不成功的的RHS 引用会导致抛出 ReferenceError异常 不成的的LHS 引用会导致自动隐式地创建一个全局变量(非严格模式下)   function foo(a) { var b = a; ...

  3. #leetcode刷题之路21-合并两个有序链表

    将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例:输入:1->2->4, 1->3->4输出:1->1->2-&g ...

  4. eclipse 配置

    访问地址        https://www.eclipse.org/ . . . 配置工作目录:存放1.项目代码    2.IDE相关配置信息 //修改编码时的字体 //修改编码格式 没有配置to ...

  5. Python中级 —— 07标准库

    标准库学习 1. The Python Standard Library[https://docs.python.org/3.5/library/] ( 3.5.5 Documentation ) 1 ...

  6. ElasticSearch优化系列五:机器设置(硬盘、CPU)

    硬盘对集群非常重要,特别是建索引多的情况.磁盘是一个服务器最慢的系统,对于写比较重的集群,磁盘很容易成为集群的瓶颈. 如果可以承担的器SSD盘,最好使用SSD盘.如果使用SSD,最好调整I/O调度算法 ...

  7. FlexPaper 里的pdf2json.exe 下载地址

    在使用FlexPaper 做在线阅读,需要使用到pdf2json.exe,将PDF转成JSON或者XML格式,网上很少下载的,现在提供一个下载的地址 http://pan.baidu.com/s/1i ...

  8. 20155226 2016-2017-2 《Java程序设计》第10周学习总结

    20155226 2016-2017-2 <Java程序设计>第10周学习总结 教材学习内容总结 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据. 程序员所作的事情 ...

  9. 20155302 《Java程序设计》实验一(Java开发环境的熟悉)实验报告

    20155302 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Jav ...

  10. 学号20155311 2016-2017-2《Java程序设计》课程总结

    学号20155311 2016-2017-2<Java程序设计>课程总结 (按顺序)每周作业链接汇总 预备作业1:(http://www.cnblogs.com/gaoziyun11/p/ ...