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.

 牛们收购了一个奶酪工厂,接下来的N个星期里,牛奶价格和劳力价格不断起伏.第i周,生产一个单位奶酪需要Ci(1≤Ci≤5000)便士.工厂有一个货栈,保存一单位奶酪,每周需要S(1≤S≤100)便士,这个费用不会变化.货栈十分强大,可以存无限量的奶酪,而且保证它们不变质.工厂接到订单,在第i周需要交付Yi(0≤Yi≤104)单位的奶酪给委托人.第i周刚生产的奶酪,以及之前的存货,都可以作为产品交付.请帮牛们计算这段时间里完成任务的最小代价.

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.

 
    第1行输入两个整数N和S.接下来N行输入Ci和Yi.

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.

    输出最少的代价.注意,可能超过32位长整型.

题解:

太经典了.

不难贪心证明,每次只可能用同一价格的存储方式.

我们只需维护一个 $minv$ ,表示价格最小值.

到下一周时,用 $minv[cur-1]$ 与 $cur_cost$ 作比较,并更新 $minv[i]$ 即可.

甚至都不用数组,几个变量即可搞定.

#include<bits/stdc++.h>
#define setIO(s) freopen(s".in","r",stdin)
#define ll long long
using namespace std;
int main()
{
// setIO("input");
int n;
ll s,c,y,cur=0,ans=0;
scanf("%d%lld",&n,&s);
scanf("%lld%lld",&c,&y);
ans+=c*y, cur=c;
for(int i=2;i<=n;++i)
{
scanf("%lld%lld",&c,&y);
cur=min(cur+s,c);
ans+=cur*y;
}
printf("%lld\n",ans);
return 0;
}

  

BZOJ 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 贪心 + 问题转化的更多相关文章

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

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

  2. bzoj1680[Usaco2005 Mar]Yogurt factory*&&bzoj1740[Usaco2005 mar]Yogurt factory 奶酪工厂*

    bzoj1680[Usaco2005 Mar]Yogurt factory bzoj1740[Usaco2005 mar]Yogurt factory 奶酪工厂 题意: n个月,每月有一个酸奶需求量( ...

  3. [Usaco2005 mar]Yogurt factory 奶酪工厂

    接下来的N(1≤N10000)星期中,奶酪工厂在第i个星期要花C_i分来生产一个单位的奶酪.约克奶酪工厂拥有一个无限大的仓库,每个星期生产的多余的奶酪都会放在这里.而且每个星期存放一个单位的奶酪要花费 ...

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

    n<=10000天每天Ci块生产一东西,S块保存一天,每天要交Yi件东西,求最少花多少钱. 这个我都不知道归哪类了.. #include<stdio.h> #include<s ...

  5. BZOJ 1680 [Usaco2005 Mar]Yogurt factory:贪心【只用考虑上一个】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1680 题意: 在接下来的n周内,第i周生产一吨酸奶的成本为c[i],订单为y[i]吨酸奶. ...

  6. bzoj 1680: [Usaco2005 Mar]Yogurt factory【贪心】

    贪心,一边读入一边更新mn,用mn更新答案,mn每次加s #include<iostream> #include<cstdio> using namespace std; in ...

  7. BZOJ1680: [Usaco2005 Mar]Yogurt factory

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

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

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

  9. BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯

    题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec  Memory Limit: 64 MB Description The c ...

随机推荐

  1. 相同的雪花 Hash

    相同的雪花 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 You may have heard that no two snowflakes are alike. ...

  2. MRO 方法解释顺序

    MRO是用在多重继承中的.考虑这种情况,整个环境中父类是两个 P1,P2 子类是两个 C1,C2 而 孙子类是G1. 我们知道 G1会从 P1,P2,C1,C2中继承属性,但是如果有多个属性重名,那么 ...

  3. Xsolla与蜗牛一起共创黑金

    Xsolla和蜗牛游戏强强合作,公布了黑金在线,是中国知名网络游戏武术时代的一个新项目. Xsolla与蜗牛黑金 2014年6月10日至20日,蜗牛的黑金在线首次在美国洛杉矶E3展会上亮相. 该游戏官 ...

  4. Apache + Tomcat + JK 集群

    原文请见http://www.cnblogs.com/dennisit/p/3370220.html 本文介绍了集群和负载均衡的基本开源实现,实现了用Apache分发请求到多个Tomcat里面相应的应 ...

  5. android 细节之 menu 之 invalidateOptionsMenu

    menu 在 android中是个很经常使用的控件,曾经自己做项目的时候通常都是将系统的menu相关方法在activity中直接删去.而且将主题换为fullscreen,然后再在layout中引入自己 ...

  6. C++ 移位运算与进制转换 浅析

    移位运算包括"逻辑移位"(logical shift)和"算术移位"(arithmetic shift). 逻辑移位:移出去的位丢弃,空缺位(vacant bi ...

  7. 解决国内android sdk无法更新,google不能的简单办法

    在国内屏蔽了很多外国站点.连google 和android都屏蔽了,做程序猿的就苦了! 只是车到山前必有路,我们也有我们的办法! 推荐一个比以下的更好的方法:红杏公益代理:http://blog.cs ...

  8. jQuery - 广告图片轮播切换

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  9. Getting Installation aborted (Status 7) ApplyParsePerms: lsetfilecon of /syst...【转】

    OTA升级失败:原文http://en.miui.com/thread-112197-1-1.html Do you get this "Status 7" error in Re ...

  10. Elasticserach 同步索引报错:ElasticSearch ClusterBlockException[blocked by: [FORBIDDEN/12/index read-only / allow delete (api)]

    欢迎关注个人微信公众号: 小哈学Java, 文末分享阿里 P8 高级架构师吐血总结的 <Java 核心知识整理&面试.pdf>资源链接!! 个人网站: https://www.ex ...