Yogurt factory
Description
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
* Lines 2..N+1: Line i+1 contains two space-separated integers: C_i and Y_i.
Output
Sample Input
4 5
88 200
89 400
97 300
91 500
Sample Output
126900
Hint
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.
#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的更多相关文章
- poj 2393 Yogurt factory
http://poj.org/problem?id=2393 Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- BZOJ1680: [Usaco2005 Mar]Yogurt factory
1680: [Usaco2005 Mar]Yogurt factory Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 106 Solved: 74[Su ...
- Yogurt factory(POJ 2393 贪心 or DP)
Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8205 Accepted: 4197 De ...
- 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂
1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 119 Solved: ...
- POJ 2393 Yogurt factory 贪心
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
- C - Yogurt factory
The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 &l ...
- 【BZOJ】1680: [Usaco2005 Mar]Yogurt factory(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1680 看不懂英文.. 题意是有n天,第i天生产的费用是c[i],要生产y[i]个产品,可以用当天的也 ...
- POJ2393 Yogurt factory 【贪心】
Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6821 Accepted: 3488 De ...
- BZOJ 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 贪心 + 问题转化
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
随机推荐
- throws、throw和try catch
在学习代理模式的时候,编写动态生成代理类.java文件时,用try{}catch(){}捕获异常发现catch(Exception e)报错,得换成catch(Throwable e),然后又查了查两 ...
- RHS 和 LHS
不成功的的RHS 引用会导致抛出 ReferenceError异常 不成的的LHS 引用会导致自动隐式地创建一个全局变量(非严格模式下) function foo(a) { var b = a; ...
- #leetcode刷题之路21-合并两个有序链表
将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例:输入:1->2->4, 1->3->4输出:1->1->2-&g ...
- eclipse 配置
访问地址 https://www.eclipse.org/ . . . 配置工作目录:存放1.项目代码 2.IDE相关配置信息 //修改编码时的字体 //修改编码格式 没有配置to ...
- Python中级 —— 07标准库
标准库学习 1. The Python Standard Library[https://docs.python.org/3.5/library/] ( 3.5.5 Documentation ) 1 ...
- ElasticSearch优化系列五:机器设置(硬盘、CPU)
硬盘对集群非常重要,特别是建索引多的情况.磁盘是一个服务器最慢的系统,对于写比较重的集群,磁盘很容易成为集群的瓶颈. 如果可以承担的器SSD盘,最好使用SSD盘.如果使用SSD,最好调整I/O调度算法 ...
- FlexPaper 里的pdf2json.exe 下载地址
在使用FlexPaper 做在线阅读,需要使用到pdf2json.exe,将PDF转成JSON或者XML格式,网上很少下载的,现在提供一个下载的地址 http://pan.baidu.com/s/1i ...
- 20155226 2016-2017-2 《Java程序设计》第10周学习总结
20155226 2016-2017-2 <Java程序设计>第10周学习总结 教材学习内容总结 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据. 程序员所作的事情 ...
- 20155302 《Java程序设计》实验一(Java开发环境的熟悉)实验报告
20155302 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Jav ...
- 学号20155311 2016-2017-2《Java程序设计》课程总结
学号20155311 2016-2017-2<Java程序设计>课程总结 (按顺序)每周作业链接汇总 预备作业1:(http://www.cnblogs.com/gaoziyun11/p/ ...