E. Goods transportation

题目连接:

http://codeforces.com/contest/724/problem/E

Description

There are n cities located along the one-way road. Cities are numbered from 1 to n in the direction of the road.

The i-th city had produced pi units of goods. No more than si units of goods can be sold in the i-th city.

For each pair of cities i and j such that 1 ≤ i < j ≤ n you can no more than once transport no more than c units of goods from the city i to the city j. Note that goods can only be transported from a city with a lesser index to the city with a larger index. You can transport goods between cities in any order.

Determine the maximum number of produced goods that can be sold in total in all the cities after a sequence of transportations.

Input

The first line of the input contains two integers n and c (1 ≤ n ≤ 10 000, 0 ≤ c ≤ 109) — the number of cities and the maximum amount of goods for a single transportation.

The second line contains n integers pi (0 ≤ pi ≤ 109) — the number of units of goods that were produced in each city.

The third line of input contains n integers si (0 ≤ si ≤ 109) — the number of units of goods that can be sold in each city.

Output

Print the maximum total number of produced goods that can be sold in all cities after a sequence of transportations.

Sample Input

3 0

1 2 3

3 2 1

Sample Output

4

Hint

题意

给你n个城市,每个城市都可以往编号比自己大的城市运送c容量为物品

每个城市可以生产最多p[i]物品,最多售卖s[i]物品

然后问你这n个物品,最多卖多少物品,一共。

题解:

如果数据范围小的话,那么显然是网络流,直接莽一波就好了

但是这个过不了。

考虑最大流等于最小割,我们可以考虑dp[i][j]表示考虑i个点,我们割掉了j个汇点的最小花费。

那么这个dp[i][j]=min(dp[i-1][j-1]+s[i],dp[i-1][j]+p[i]+cj)

然后滚动数组优化一下就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n;
long long c,p[maxn],s[maxn],f[maxn],ans,sum;
int main()
{
cin>>n>>c;
for(int i=1;i<=n;i++)cin>>p[i];
for(int i=1;i<=n;i++)cin>>s[i];
for(int i=1;i<=n;i++){
f[i]=1e18;
for(int j=i;j>=1;j--)
f[j]=min(f[j]+j*c+p[i],f[j-1]+s[i]);
f[0]+=p[i];
}
ans=1e18;
for(int i=0;i<=n;i++)
ans=min(ans,f[i]);
cout<<ans<<endl;
}

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation 动态规划的更多相关文章

  1. CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

    1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort    暴力枚举,水 1.题意:n*m的数组, ...

  2. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)D Dense Subsequence

    传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最 ...

  3. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort

    链接 题意:输入n,m,表示一个n行m列的矩阵,每一行数字都是1-m,顺序可能是乱的,每一行可以交换任意2个数的位置,并且可以交换任意2列的所有数 问是否可以使每一行严格递增 思路:暴力枚举所有可能的 ...

  4. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing

    我不告诉你这个链接是什么 分析:模拟可以过,但是好烦啊..不会写.还有一个扩展欧几里得的方法,见下: 假设光线没有反射,而是对应的感应器镜面对称了一下的话 左下角红色的地方是原始的的方格,剩下的三个格 ...

  5. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)

    http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...

  6. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation (非官方贪心解法)

    题目链接:http://codeforces.com/contest/724/problem/E 题目大意: 有n个城市,每个城市有pi件商品,最多能出售si件商品,对于任意一队城市i,j,其中i&l ...

  7. Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)

    传送门 Description You are given names of two days of the week. Please, determine whether it is possibl ...

  8. Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort(暴力)

    传送门 Description You are given a table consisting of n rows and m columns. Numbers in each row form a ...

  9. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B

    Description You are given a table consisting of n rows and m columns. Numbers in each row form a per ...

  10. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A

    Description You are given names of two days of the week. Please, determine whether it is possible th ...

随机推荐

  1. crontab定时任务2_net

    2017年2月25日, 星期六 crontab定时任务2_net 1.先来一个小小的例子 查看当前路径: [root@root test]# pwd /home/admin/test [root@ro ...

  2. 正则tips

    在啃Sizzle源码,被几个正则表达式给难住了,写了一下正则demo,记录一下 1,按照定义[]和(?:)里的内容不计入捕获组的数目 2,捕获组的计数顺序是,从大到小,同级从左到右 例如 var re ...

  3. CSS-3 文字阴影—text-shadow 的使用

    text-shadow还没有出现的时候,大家在网页中的阴影就是用ps一张图片作为背景.那么现在有了CSS3的这个属性,日后我们的工作会更简洁些. text-shadow之前出现过,不过不久就被Pass ...

  4. Guava HashMultiset(MultiSet)

    multiset:多重集合,和set唯一的不同是 set 集合中一个值只能出现一次,而multiset多重集合中一个值可以出现多次.一个典型的应用就是统计单词出现次数 举例: public class ...

  5. 洛谷 P3916 【图的遍历】反向加边+dfs

    前言: 对于这类带环的图,一般记忆化搜索不能很好的对所有遍历的边进行更新取值.因为环上的点可以相互到达,所以他们的答案因当是同步更新的,而dfs一旦你回溯完环上某个点就不会在更新这个点的答案了,做不到 ...

  6. Python 入门基础6 --字符编码、文件操作1

    今日内容: 1.字符编码 2.字符与字节 3.文件操作 一.字符编码 了解: cpu:将数据渲染给用户 内存:临时存放数据,断电消失 硬盘:永久存放数据,断电后不消失 1.1 什么是编码? 人类能够识 ...

  7. Javascript - Vue - vue对象的生命周期

    vue对象的生命周期 从vue的创建到销毁会经过一系列的事件,这是vue对象的生命周期. 创建期间的生命周期函数 <div id="box">    <h3 id ...

  8. 【SVN】命令行忽略不必要的文件和文件夹

    SVN命令参考:   https://www.cnblogs.com/wlsxmhz/p/5775393.html 我们需要明白命令行设置忽略文件和文件夹是通过设置svn:ignore属性设置的,pr ...

  9. Ansible Tower系列 二(安装 Tower)【转】

    文档:http://docs.ansible.com/ansible-tower/ 安装前检查 python版本为2.6 保持网络畅通 内存预留充足 安装用户为root 软件下载 下载地址:http: ...

  10. C# UDP广播消息

    首先是发送端: /// <summary> /// 发送UDP消息 /// </summary> /// <param name="msg">消 ...