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;
}

转载于:https://www.cnblogs.com/qscqesze/p/5946787.html

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation 动态规划相关推荐

  1. codeforces Intel Code Challenge Final Round (div.1 + div.2 combined)

    比赛水掉3题rk559 rating+115 赛后切掉C n年没打cf了终于又重新变蓝了,果然太弱... 1.A题  Checking the Calendar 给定两个星期几,问是否可能分别是两个月 ...

  2. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) B. Verse Pattern 水题

    B. Verse Pattern 题目连接: http://codeforces.com/contest/722/problem/B Description You are given a text ...

  3. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C 倒序并查集

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)切题报告(A-B题)

    这是我第二次参加CF比赛,也是第一次写博客,写得不好,望各位大佬海涵. A. Single Wildcard Pattern Matching 原题链接 这道题,这是难到让人无法直视,太水了. 题目大 ...

  5. Codeforces Round #586 (Div. 1 + Div. 2) B. Multiplication Table 思维 + 公式

    传送门 文章目录 题意: 思路: 题意: 给你一个n∗nn*nn∗n的矩阵,每个位置由ai∗aja_i*a_jai​∗aj​得来,主对角线为000,让你求出来aia_iai​. n≤1e3n\le1e ...

  6. Codeforces Round #586 (Div. 1 + Div. 2) D. Alex and Julian 数学 + 思维

    传送门 文章目录 题意: 思路: 题意: 给你一个无限个点的坐标轴,一个集合BBB,如果存在∣i−j∣=bk|i-j|=b_k∣i−j∣=bk​的话,那么i,ji,ji,j之间就连边.现在问你至少要从 ...

  7. Codeforces Round #733 (Div. 1 + Div. 2) E. Minimax 分情况讨论 + 思维

    传送门 文章目录 题意: 思路: 题意: 给你一个串,你可以随意安排这个串,使得这个串的每个前缀的kmpkmpkmp数组最大值最小,定义为f(a)f(a)f(a),并且字典序最小,输出安排之后的串. ...

  8. Ozon Tech Challenge 2020 (Div.1 + Div.2) F. Kuroni and the Punishment 随机化

    传送门 文章目录 题意: 思路: 题意: 给你nnn个数,每次操作可以选择将某个数+1,−1+1,-1+1,−1,求最少进行多少次操作使得所有数都为正数且gcd>1gcd>1gcd> ...

  9. Ozon Tech Challenge 2020 (Div.1 + Div.2) E.Kuroni and the Score Distribution 构造

    传送门 文章目录 题意: 思路: 题意: 思路: 不难想到,长度为nnn的数组最多的满足条件的三元组序列是1,2,3....,n1,2,3....,n1,2,3....,n,对于每一个位置贡献为i−1 ...

最新文章

  1. tradingview Vue
  2. C# string.Empty
  3. 聊聊tomcat jdbc pool的默认参数及poolSweeper
  4. C语言'\0'(偶遇坑)
  5. NET问答: C# 中是否有 format json 的类库?
  6. 视频监控系统中的平台服务器,【视频监控主机 网络视频集中管理平台服务器】 - 太平洋安防网...
  7. linux 删除提示没有那个文件或目录,rm 无法删除没有那个文件或目录
  8. (一)源码下载,编译,安装
  9. Mysql改写子查询SQL优化案例
  10. 【python自动化第十篇:】
  11. 一份来自滴滴运维工程师的监控系统建设心得
  12. 系统自动校时后发广播android,校园定时播放软件
  13. Java 14中对switch的增强,终于可以不写break了
  14. 杂谈随感-3:不同的角色,不同的价值体现
  15. php微信上传图文素材,php使用curl 上传微信公共平台素材文件
  16. 使用scrapy框架爬虫实战
  17. 只有A2L文件如何连接INCA
  18. app营销应该这样做(读书笔记)
  19. 透明代理、匿名代理、混淆代理、高匿代理有什么区别?
  20. 视频超分——03 SPMC

热门文章

  1. 哪里可以接到python的活干-越忙越穷?赶紧把瞎忙活的事情交给Python吧!
  2. python画函数曲线-Python 绘制你想要的数学函数图形
  3. python入门教程非常详细-Python该怎么入门?Python入门教程(非常详细)
  4. r语言和python-R语言和Python一块学习会弄混吗
  5. python网络爬虫的基本步骤-Python网络爬虫与信息提取(一)(入门篇)
  6. python流程控制-python简单流程控制
  7. python中文名字叫什么-Python为什么取名为Python,很少人知道
  8. python matplotlib散点图-python-Matplotlib散点图图例
  9. 看漫画学python电子书-看漫画学Python(有趣有料好玩好用全彩版)
  10. python基础单词-学习Python必背的初级单词有哪些?