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.
 
 
题解:
不难发现每个产品的价格(在不同的周)都是一次函数的变化,所以我们只要对于横坐标x(周),求出那一周生产的产品在这周花费最小,然后用花费乘以对应的数量就可以了。
 
代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#define ll long long
#define MAXN 50010
using namespace std;
int cost[MAXN],mai[MAXN];
int n,s;
ll ans=;
int main()
{
scanf("%d%d",&n,&s);
for(int i=;i<=n;i++){
scanf("%d%d",&cost[i],&mai[i]);
}
for(int wek=;wek<=n;wek++){
int minn=<<;
for(int i=;i<=wek;i++){
minn=min(minn,cost[i]+s*(wek-i));
}
ans+=minn*mai[wek];
}
printf("%lld",ans);
return ;
}

POJ - 2393Yogurt factory的更多相关文章

  1. POJ Widget Factory 【求解模线性方程】

    传送门:http://poj.org/problem?id=2947 Widget Factory Time Limit: 7000MS   Memory Limit: 65536K Total Su ...

  2. POJ 2947-Widget Factory(高斯消元解同余方程式)

    题目地址:id=2947">POJ 2947 题意:N种物品.M条记录,接写来M行,每行有K.Start,End,表述从星期Start到星期End,做了K件物品.接下来的K个数为物品的 ...

  3. poj 2393 Yogurt factory

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

  4. POJ 3436 ACM Computer Factory (网络流,最大流)

    POJ 3436 ACM Computer Factory (网络流,最大流) Description As you know, all the computers used for ACM cont ...

  5. 【POJ】2947 Widget Factory(高斯消元)

    http://poj.org/problem?id=2947 各种逗啊..还好1a了.. 题意我就不说了,百度一大把. 转换为mod的方程组,即 (x[1,1]*a[1])+(x[1,2]*a[2]) ...

  6. Poj 3436 ACM Computer Factory (最大流)

    题目链接: Poj 3436 ACM Computer Factory 题目描述: n个工厂,每个工厂能把电脑s态转化为d态,每个电脑有p个部件,问整个工厂系统在每个小时内最多能加工多少台电脑? 解题 ...

  7. A - ACM Computer Factory POJ - 3436 网络流

    A - ACM Computer Factory POJ - 3436 As you know, all the computers used for ACM contests must be ide ...

  8. POJ 3436:ACM Computer Factory(最大流记录路径)

    http://poj.org/problem?id=3436 题意:题意很难懂.给出P N.接下来N行代表N个机器,每一行有2*P+1个数字 第一个数代表容量,第2~P+1个数代表输入,第P+2到2* ...

  9. POJ 3464 ACM Computer Factory

    ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4829 Accepted: 1641 ...

随机推荐

  1. Python基础:Python运行的两种基本方式

    完成Python的安装之后,我们可以开始编写Python代码以及运行Python程序了.我们来看一下运行Python具体有哪几种方式 1.REPL 所谓REPL即read.eva.print.loop ...

  2. 那些年,我们误解的 JavaScript 闭包

    说到闭包,大部分的初始者,都是谈虎色变的.最近对闭包,有了自己的理解,就感觉.其实我们误解闭包.也被网上各种说的闭包的解释给搞迷糊. 一句话:要想理解一个东西还是看权威的东西. 下面我来通俗的讲解一个 ...

  3. Ajax请求纯文本问题

    今天在学习Ajax时遇到一个问题: Ajax有个open(method String,url,boolean)方法,此方法有三个参数: 参数一:提交数据的请求,有GET和POST请求 GET:获取数据 ...

  4. Java基础语法(总结篇)

    关键字&标识符 关键字的概念与特征 概念:Java关键字是事先定义好的对Java的编译器有特殊的意义,他们用来表示一种数据类型,或者表示程序的结构等,关键字不能用作变量名.方法名.类名.包名和 ...

  5. 虚拟化(三) -vsphere套件的安装注意及使用

    https://www.cnblogs.com/zhrngM/p/9547958.html [转]虚拟化(三):vsphere套件的安装注意及使用 vsphere套件里面主要的组件有esxi.vcen ...

  6. 动态设置 view 在布局中位置

    一.概述 有时项目需要动态设置一个 底部列表,比如 popupwindow ,listview 底部显示 ,所以记录一下 此处, android.support.v7.widget.CardView ...

  7. Java-HashSet集合中的几种遍历方式

    //我们先创建一个set集合 public static void main(String[] args) { Set<Integer> sets = new HashSet<> ...

  8. SpringAop实现公共字段填充

    一.说明 项目中经常会有一些放在缓存中的公共字段需要进行填充,我们知道mybatis-plus很方便地可以实现公共字段填充.在这里我定义了一个字段填充的注解,当我们需要进行数据填充的时候只要在方法上打 ...

  9. ansible-playbook流程控制-loops循环使用

    1. ansible-playbook流程控制-loops循环使用    有时你想要多次重复任务.在计算机编程中,这称为循环.common ansible循环包括使用文件模块更改多个文件和/或目录的所 ...

  10. 跟我学SpringCloud | 第十八篇:微服务 Docker 化之基础环境

    1. 容器化 Docker 的横空出世,给了容器技术带来了质的飞跃,Docker 标准化了服务的基础设施,统一了应用的打包分发,部署以及操作系统相关类库等,解决了测试生产部署时环境差异的问题.对于运维 ...