Yogurt factory
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 16669   Accepted: 8176

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. 

看了几篇博客才有了点思路, 每天生产的酸奶是那一天的,要比较今天的 C 与  Cmin + S  的关系, Cmin是前几个周存储在仓库里的酸奶最小成本, 随着时间的推移,Cin+S , 直到他不再小于当前的C, 替换掉。
就是一直再权衡当前C与Cmin+S, 求得最小成本。

#include <iostream>
#include <stdio.h> using namespace std; int main()
{
long long ans;
int n, s, y, c, minc;
while(scanf("%d%d", &n, &s)!=-)
{
ans=; minc=;
for(int i=; i<n; i++)
{
scanf("%d%d", &c, &y);
if(c > minc +s)
c = minc + s;
minc = c;
ans += c*y;
}
printf("%lld\n", ans);
}
return ;
}

poj_2393 Yogurt factory 贪心的更多相关文章

  1. POJ 2393 Yogurt factory 贪心

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

  2. poj-2393 Yogurt factory (贪心)

    http://poj.org/problem?id=2393 奶牛们有一个工厂用来生产奶酪,接下来的N周时间里,在第i周生产1 单元的奶酪需要花费ci,同时它们也有一个储存室,奶酪放在那永远不会坏,并 ...

  3. POJ-2393 Yogurt factory 贪心问题

    题目链接:https://cn.vjudge.net/problem/POJ-2393 题意 有一个生产酸奶的工厂,还有一个酸奶放在其中不会坏的储存室 每一单元酸奶存放价格为每周s元,在接下来的N周时 ...

  4. Yogurt factory(POJ 2393 贪心 or DP)

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8205   Accepted: 4197 De ...

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

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

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

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

  7. POJ2393 Yogurt factory 【贪心】

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6821   Accepted: 3488 De ...

  8. BZOJ1680: [Usaco2005 Mar]Yogurt factory

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

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

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

随机推荐

  1. App 性能测试分享

    在本文内,主要以Android性能测试为主进行分析 一.性能测试包含 1.启动时间测试   测试场景包括 - - - 首次安装启动时间.冷启动.热启动测试 2.页面响应时间:   用户从点击一个控件, ...

  2. 个人hexo博客(静态,无后台)搭建

    博客搭建 1.工具安装 安装Node.js,其中包含Node.js和npm(包管理器) 利用npm安装cnpm(淘宝的npm,速度在国内更快) npm install -g cnpm --regist ...

  3. Android | 教你如何开发扫二维码功能

    前言   最近要做一个停车场扫码收费的app,在网上搜了一圈,首先接触到了ZXing,上手试了下,集成过程不复杂,但是感觉效果欠佳,比如距离稍微远点儿就扫不出来了,另外角度对的不好,反光或者光线比较暗 ...

  4. PowerShell入门简介

    文章更新于:2020-03-03 一.PowerShell简介 说实话,我总感觉 PowerShell 是 cmd 的加强版,但是看官方介绍,功能甚是强大,用处有待我们发掘. 二.PowerShell ...

  5. python3(二十八)manyExten

    """ 多重继承 """ __author__ = 'shaozhiqi' # start ------------------------ ...

  6. OO第三单元作业分析

    一.JML的理论基础应用工具链 JML是用于对Java程序进行规格化设计的一种表示语言.基于Larch方法构建. (1)注释 JML以javadoc注释的方式来表示规格,每行都以@起头.有两种注释方式 ...

  7. https的秘钥公钥以及之间的会话流程

      一 共享秘钥 1.1 概念 共享秘钥和我们生活中同一把锁的钥匙概念类似,对同一把锁来说,加锁时使用什么钥匙,解锁也必须使用同样的钥匙. 1.2 共享秘钥在HTTP传输中的缺点 以共享密钥方式加密时 ...

  8. redis中的分布式锁

    分布式锁的实现场景 在平时的开发中,对于高并发的开发场景,我们不可避免要加锁进行处理,当然redis中也是不可避免的,下面是我总结出来的几种锁的场景 Redis分布式锁方案一 使用Redis实现分布式 ...

  9. 对象中属性 加锁 用:volatile 关键词修饰 而 不用 synchronized 加锁

    一个对象中有一个状态 属性,现在业务需求 存在多线程来修改 和 拿去 这个状态 的值,这种情况如果加锁怎么加? 一种是 在 set 和get 这个状态的 方法那加 synchronized . 还有一 ...

  10. 《SQL 反模式》 学习笔记

    第一章 引言 GoF 所著的的<设计模式>,在软件领域引入了"设计模式"(design pattern)的概念. 而后,Andrew Koenig 在 1995 年造了 ...