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. MySQL二进制日志挖掘器BinlogMiner 1.0发布了。

    MySQL从2014年开始超越SQL Server, 占据DB-Engines数据库流行度排行榜第二名, 是一种非常流行的关系型数据库, 特别是在互联网领域, 是一种应该掌握的数据库系统.最近在学My ...

  2. 会计的疑惑--BigDecimal的秘密

    为了提供公司的财务信息化,公司A上线了一套自主研发的财务系统,上班第一天,财务C姐就发现了情况不对:几项支出都对,但支出总和一直为0,赶紧向大老板报告.大老板勃然大怒,责令技术部门今天必须解决,小B负 ...

  3. scp建立安全信任关系

    1. 在机器Client上root用户执行ssh-keygen命令,生成建立安全信任关系的证书. [root@Client root]# ssh-keygen -b 1024 -t rsa Gener ...

  4. zipkin+elk微服务日志收集分析系统

    docker安装elk日志分析系统 在win10上安装docker环境 tip:win7/8 win7.win8 系统 win7.win8 等需要利用 docker toolbox 来安装,国内可以使 ...

  5. 基于Linux系统--web环境搭建

    上线部署文档 数据库部分1.下载Mysql服务    #yum  install  mysql-server 2.更改             /etc/my.cnf 3.启动Mysql        ...

  6. Maven 梳理 - maven新建web项目提示"javax.servlet.http.HttpServlet" was not found on the Java Build Path

    方法一: <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api&l ...

  7. Android开发——Kotlin开发APP使用笔记

    之前一直使用java来开发Android项目,学了新的kotlin语言,前来试一试,并说一下kotlin对Android的一些功能增强 创建项目 我使用的是Android Studio3.0+,所以默 ...

  8. C# HttpWebRequest 后台调用接口上传大文件以及其他参数

    直接上代码,包各位看客能用!!! 1.首先请求参数的封装 /// <summary> /// 上传文件 - 请求参数类 /// </summary> public class ...

  9. Go语言操作MySQL

    MySQL是常用的关系型数据库,本文介绍了Go语言如何操作MySQL数据库. Go操作MySQL 连接 Go语言中的database/sql包提供了保证SQL或类SQL数据库的泛用接口,并不提供具体的 ...

  10. ieTESTER浏览器使用ie6崩溃问题

    打开浏览器在选项--internet属性--连接--局域网设置--将自动检测设置的对勾勾掉就可以  重启下浏览器