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. 
 
 
题目意思:由于市场原因牛奶的生产价格会有所波动,要求在将来的n周里,该公司拥有一个足够大的仓库储存制好的牛奶,每个单位的牛奶每周储存

 所需的费用为s,现给出将来n周生产每单位牛奶的价格及客户所需的数量(即提前知道了下面几周的牛奶价格和客户需求!!!),求出该公司将来n周内所要支付的最小生产值。
 
解题思路:这是一道贪心题,贪心策略,每一个周只需要和下一个周对比,每一次更新下一个相邻的周,因为若下一个周被更新了,那么下一个周可以用来更新剩下的周,所以每一个周只需要对下一个周负责就可以了,可以看成一种带有传递性的比较。
 
上代码:

 #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的更多相关文章

  1. poj 2393 Yogurt factory

    http://poj.org/problem?id=2393 Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  2. BZOJ1680: [Usaco2005 Mar]Yogurt factory

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

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

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

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

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

  5. POJ 2393 Yogurt factory 贪心

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

  6. C - Yogurt factory

    The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 &l ...

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

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

  8. POJ2393 Yogurt factory 【贪心】

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

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

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

随机推荐

  1. Vue 源码分析——构造函数原型

    在执行 npm run dev 的时候 根据script/config.js 文件中的配置 'web-full-dev': { entry: resolve('web/entry-runtime-wi ...

  2. vue项目获取当前地址栏参数(非路由传参)

    项目中遇到一个需求,就是另一个管理系统带参直接单纯的跳转跳转到vue pc项目中的某个页面,后再初始化查询数据,参数以地址栏的形式传入 管理系统:打开新地址地址 let obj = { id: 21, ...

  3. 嵌入式STM32开发环境之Keil5的安装(附资源)--

    全文copy,原文见https://blog.csdn.net/weixin_42602730/article/details/81007685 --------------------------- ...

  4. Elastix 2.4 双服务器热备搭建文档

    一.     背景知识 本文档将会用到以下两个重要的组件: a)     DRBD DRBD的全称为:Distributed Replicated Block Device,意为分布式块设备复制, D ...

  5. PHP代码优化—getter 和 setter

    PHP中要实现类似于Java中的getter和setter有多种方法,比较常用的有: 直接箭头->调用属性(最常用),不管有没有声明这个属性,都可以使用,但会报Notice级别的错误 $dog ...

  6. Oracle入门第三天(上)——多表查询与分组函数

    一.多表查询 所有的连接分析,参考之前随笔:http://www.cnblogs.com/jiangbei/p/7420136.html 1.笛卡尔积 select last_name, depart ...

  7. 20155203 2016-2017-2 《Java程序设计》第1周学习总结

    20155203 2016-2017-2 <Java程序设计>第1周学习总结 学习目标 - 了解Java基础知识[第一章] Java是各应用平台的基础,Java分为三大平台:Java三大平 ...

  8. Java程序设计 第16周 课堂实践

    Java程序设计 第16周 课堂实践 -- 数据库2 课堂实践任务2 查询world数据库,获得人口超过500万的所有城市的列表. 代码分析 实现查询数据库需要我们修改Message.java,Mes ...

  9. 第9周 实现PWD命令

    第9周 实现PWD命令 码云链接:https://gitee.com/bestiisjava2017/laura5332/blob/master/%E4%BF%A1%E6%81%AF%E5%AE%89 ...

  10. Qt 信号槽传递自定义结构体

    Qt 在信号和槽中使用自己定义的结构体