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. linux golang

    wget -c http://www.golangtc.com/static/go/go1.3.linux-386.tar.gz #下载32位Linux的够源码包 tar -zxvf go1.1.li ...

  2. JS基础---到底什么是闭包?它是如何形成的?

    1.闭包 先看一个简单的例子 function a() { var i = 0; function b() { alert(++i); } return b; }var c = a(); c(); 这 ...

  3. Python open操作文件

    操作文件 # coding=utf-8 支持中文 """ China Japan France England """ f = open(& ...

  4. java 二维数组的行列长度

    在 java 中,其实只有一维数组,而二维数组是在一维数组中嵌套实现的.比如 int[][] a = {{},{},{},{}} 要取行数和某一行的列数可以 : int rowLen = a.leng ...

  5. confirm("确定要删除吗?") _详解

    具体代码如下: html代码: <div class="deletes">删除</div> js代码: <script type="text ...

  6. 力扣(LeetCode) 905. 按奇偶排序数组

    给定一个非负整数数组 A,返回一个由 A 的所有偶数元素组成的数组,后面跟 A 的所有奇数元素. 你可以返回满足此条件的任何数组作为答案. 示例: 输入:[3,1,2,4] 输出:[2,4,3,1] ...

  7. ubuntu vscode chrome 显示color emoji

    win10 下vscode默认就可以显示color emoji, 真是亲儿子啊. 但linux下默认是显示黑白的. 绕了一些弯路之后,发现最简单的办法是: 1 下载google noto字体全集    ...

  8. Creazy Ideas 智能汽车和智能交通

    1.现在无人驾驶靠的是摄像头监测障碍物,计算可行路线(这个结论是看到相关视频中百度无人驾驶测试中大大的摄像头推测的,非确切信息).而非像人一样对客观事物的认知学习得到障碍物的信息,如果能将AI融入进去 ...

  9. JAVA基础知识总结:二十二

    一.反射机制 1.概念 反射机制指的是程序在运行的过程中,对于任意一个类,都能够知道这个类对应的所有的属性和方法:对于任意一个对象,都能够调用其中的任意的方法和属性,在Java中,把这种动态获取信息以 ...

  10. JAVA基础知识总结:十二

    一.String类 字符串是一种特殊的对象,一旦被初始化就不能被改变了 字符串常量存储于常量池中 二.StringBuffer类 是一个字符串缓冲区,相当于一个容器 特点 a.可以对字符串进行增加和删 ...