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】【有趣的模块】【Requests】无状态 & 无连接

    无状态:原来的Web是静态,后来换成动态的就需要保存一些上下文信息,session和cookie应运而生 无连接:原来为了请求结束后赶紧把资源让出去,后来发现每次请求中有相同的小请求时候再重复执行(而 ...

  2. RESTful 个人理解总结

    一.什么是RESTful 面向资源 简单的说:RESTful是一种架构的规范与约束.原则,符合这种规范的架构就是RESTful架构.   先看REST是什么意思,英文Representational ...

  3. 前端html5/css基础知识

    https://www.cnblogs.com/clschao/articles/10073124.html

  4. django会话session

    因为因特网HTTP协议的特性,每一次来自于用户浏览器的请求(request)都是无状态的.独立的.通俗地说,就是无法保存用户状态,后台服务器根本就不知道当前请求和以前及以后请求是否来自同一用户.对于静 ...

  5. 使用Hexo搭建一个简单的博客(一)

    搭建好简洁的博客框架后,回看时发现,简洁之中透露着一丝丝简陋,好的,网上关于丰富hexo的文章也很多 记录一下自己的一些瞎操作. 在你的hexo目录下,你可以看到themes文件夹里有个默认的land ...

  6. python静态方法、类方法

    常规: class Dog(object): def __init__(self,name): self.name=name def eat(self): print('%s is eating'%s ...

  7. Qt网络应用开发初步

      应用层的网络协议,如HTTP/FTP/SMTP等简称"应用协议",他们运行在TCP/UDP之上,从Qt5开始,已经不再分别提供QHttp类,QFtp类,应用层的编程使用QNet ...

  8. (25)线程---local数据隔离

    线程之间本身是数据共享的,当多个线程同时修改一份数据的时候,数据就可能不 准确,特别是线程量特别大的时候,为了保证数据准确性: (1) 通过线程锁Lock (2)通过local数据隔离 from th ...

  9. scala文件读取报错“java.nio.charset.MalformedInputException: Input length = 1”

    今天写spark程序的时候遇到了一个问题就是,读取文件的时候报了一个错:“Exception in thread "main" java.nio.charset.Malformed ...

  10. Spring Cloud之配置中心搭建

    一.配置中心服务端搭建 1)引入相关Maven坐标 <dependency> <groupId>org.springframework.cloud</groupId> ...