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. 【css】 如何修改select的样式

    select { /*清除select默认样式*/ appearance:none; -moz-appearance:none; -webkit-appearance:none; -ms-appear ...

  2. C++练习 | 运算符重载练习(字符串相关)

    #include <iostream> #include <cmath> #include <cstring> #include <string> #i ...

  3. $.post({})请求springmvc -5.x 的方法,没有 返回数据的情况

    转载请注明出处,毕竟调试了一天 今天用$.post({})传递参数,账号和密码来验证登录,验证成功返回1,验证不成功返回0,结果,$.post({}),的回调函数一直无法执行,但是原来是可以的,不重大 ...

  4. iOS 12.0-12.1.2 越狱教程

    unc0ver V3.0.0~b29 越狱工具已经开始公测,支持搭载 A8X-A11 处理器的 iOS 12.0-12.1.2 设备完整越狱,Cydia 商店和 Substrate 插件可正常安装并运 ...

  5. 【postgresql的使用】

    #安装: #初始化: #允许远程登录: #创建数据库并指定用户 #创建用户 #列出数据库 #进入数据库 #查询数据 #or(或)查询 #and ,or(和,或查询) #表连接 #内,外(左右),交叉连 ...

  6. WOT干货大放送:大数据架构发展趋势及探索实践分享

      WOT大数据处理技术分会场,PingCAP CTO黄东旭.易观智库CTO郭炜.Mob开发者服务平台技术副总监林荣波.宜信技术研发中心高级架构师王东及商助科技(99Click)顾问总监郑泉五位讲师, ...

  7. 使用树莓派拍摄延时动画,制作GIF图

    本期教大家将编写一个小脚本用树莓派来捕获多个图像,然后可以将这些图像组合成动画GIF,使用延时摄影功能,可以在几秒钟内查看非常慢的事情. 我们需要用到ImageMagick,这是一个用于图像处理的命令 ...

  8. PTA(BasicLevel)-1007素数对猜想

    一 问题描述-素数对 让我们定义素数差d​n​​为:d​n​​=p​n+1​​−p​n​​,其中p​i​​是第i个素数.显然有d​1​​=1,且对于n>1有d​n​​是偶数.“素数对猜想”认为“ ...

  9. 基于fork(),execvp()和wait()实现类linux下的bash——mybash

    基于fork(),execvp()和wait()实现类linux下的bash--mybash 预备知识 fork():fork()函数通过系统调用创建一个与原来进程几乎完全相同的进程,也就是两个进程可 ...

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

    20155215 2016-2017-2 <Java程序设计>第X周学习总结 教材学习内容总结 第六章 继承,避免多个类间重复定义共同行为.子类继承父类,再扩充(extends)其他行为. ...