Yogurt factory
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 14771   Accepted: 7437

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. 

Source

 
******每次判断哪个地方更适合做单个奶酪,就将从现在开始及以后都按这套方案走,如果遇到更优的方案当然就修改方案啦,这就是传说中的贪心啦。
 
 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int i,j,n,c[],w[],s,k = ;
long long int ans = ;
int main()
{
scanf("%d %d",&n,&s);
for(i = ;i <= n;i++)
{
scanf("%d %d",&c[i],&w[i]);
if(c[i] <= c[k] + (i - k) * s)
k = i;
ans += c[k] * w[i] + (i - k) * s * w[i];
}
printf("%lld",ans);
return ;
}

POJ2393奶酪工厂的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. poj2393

    题目大意: 奶酪工厂 奶牛买了一个奶酪工厂制作全世界有名的Yucky酸奶,在接下来的N周(1<=N<=10000),牛奶的价格和工作将会受到波动例如他将花费C_i (1 <= C_i ...

  7. AOJ 0558 Cheese【BFS】

    在H * W的地图上有N个奶酪工厂,分别生产硬度为1-N的奶酪.有一只吃货老鼠准备从老鼠洞出发吃遍每一个工厂的奶酪.老鼠有一个体力值,初始时为1,每吃一个工厂的奶酪体力值增加1(每个工厂只能吃一次), ...

  8. BFS AOJ 0558 Chess

    AOJ 0558 Chess http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0558    在H * W的地图上有N个奶酪工厂,每个 ...

  9. POJ 2393 Yogurt factory 贪心

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

随机推荐

  1. python学习打卡 day12 生成器

    本节主要内容 : 生成器 生成器函数 各种推导式 生成器表达式 一.生成器 什么是生成器.生成器的本质就是迭代器. 在python中有三种方式来获取生成器: 1.通过生成器函数 2.通过各种推导式来实 ...

  2. git core.autocrlf配置 解决Windows和Linux(Mac)换行问题

    格式化 格式化是许多开发人员在协作时,特别是在跨平台情况下,遇到的令人头疼的细小问题. 由于编辑器的不同或者Windows程序员在跨平台项目中的文件行尾加入了回车换行符, 一些细微的空格变化会不经意地 ...

  3. _pvp_gap_aura

    该表可以用于控制区域内平衡,举个例子,当一个区域内超过limitHP的LM玩家个数为10,部落玩家个数为8,则阵营人数差为2,人数少的部落,所有部落玩家获得2层aura光环 zone 区域ID aur ...

  4. Codeforces Round #271 (Div. 2) E. Pillars 线段树优化dp

    E. Pillars time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  5. python中while循环运算符及格式化输出

    一,while循环 while 条件: while语句块(循环体) 运行: 判断你给的条件是否为真,如果真则执行循环体.否则跳出循环. 执行完循环体之后再次判断条件是否为真 例子1 我们玩联盟的时候喷 ...

  6. 自定义 Git - 配置 Git

    用git config配置 Git,要做的第一件事就是设置名字和邮箱地址: $ git config --global user.name "John Doe" $ git con ...

  7. BMP操作_测试

    1.参考网址: http://blog.sina.com.cn/s/blog_678b377a0100mlyb.html http://blog.csdn.net/weiyongtao87/artic ...

  8. List、Map、Set的区别与联系

    重复和有序 List 存储的元素是有顺序的,并且值允许重复: Map 元素按键值对存储,无放入顺序 ,它的键是不允许重复的,但是值是允许重复的: Set 存储的元素是无顺序的,并且不允许重复,元素虽然 ...

  9. vue中eslintrc.js配置最详细介绍

    本文是对vue项目中自带文件eslintrc.js的内容解析, 介绍了各个eslint配置项的作用,以及为什么这样设置. 比较详细,看完能对eslint有较为全面的了解,基本解除对该文件的疑惑. /* ...

  10. 牛客OI周赛6-提高组 B 践踏

    践踏 思路: 如果k不为0, 那么就是对k取模意义下的区间更新, 单点查询 否则, 就是普通的区间更新, 单点查询 代码: #pragma GCC optimize(2) #pragma GCC op ...