链接:https://codeforces.com/contest/1249/problem/E

You are planning to buy an apartment in a nn-floor building. The floors are numbered from 11 to nn from the bottom to the top. At first for each floor you want to know the minimum total time to reach it from the first (the bottom) floor.

Let:

  • aiai for all ii from 11 to n−1n−1 be the time required to go from the ii-th floor to the (i+1)(i+1)-th one (and from the (i+1)(i+1)-th to the ii-th as well) using the stairs;
  • bibi for all ii from 11 to n−1n−1 be the time required to go from the ii-th floor to the (i+1)(i+1)-th one (and from the (i+1)(i+1)-th to the ii-th as well) using the elevator, also there is a value cc — time overhead for elevator usage (you need to wait for it, the elevator doors are too slow!).

In one move, you can go from the floor you are staying at xx to any floor yy (x≠yx≠y) in two different ways:

  • If you are using the stairs, just sum up the corresponding values of aiai. Formally, it will take ∑i=min(x,y)max(x,y)−1ai∑i=min(x,y)max(x,y)−1ai time units.
  • If you are using the elevator, just sum up cc and the corresponding values of bibi. Formally, it will take c+∑i=min(x,y)max(x,y)−1bic+∑i=min(x,y)max(x,y)−1bi time units.

You can perform as many moves as you want (possibly zero).

So your task is for each ii to determine the minimum total time it takes to reach the ii-th floor from the 11-st (bottom) floor.

Input

The first line of the input contains two integers nn and cc (2≤n≤2⋅105,1≤c≤10002≤n≤2⋅105,1≤c≤1000) — the number of floors in the building and the time overhead for the elevator rides.

The second line of the input contains n−1n−1 integers a1,a2,…,an−1a1,a2,…,an−1 (1≤ai≤10001≤ai≤1000), where aiai is the time required to go from the ii-th floor to the (i+1)(i+1)-th one (and from the (i+1)(i+1)-th to the ii-th as well) using the stairs.

The third line of the input contains n−1n−1 integers b1,b2,…,bn−1b1,b2,…,bn−1 (1≤bi≤10001≤bi≤1000), where bibi is the time required to go from the ii-th floor to the (i+1)(i+1)-th one (and from the (i+1)(i+1)-th to the ii-th as well) using the elevator.

Output

Print nn integers t1,t2,…,tnt1,t2,…,tn, where titi is the minimum total time to reach the ii-th floor from the first floor if you can perform as many moves as you want.

Examples

input

Copy

10 2
7 6 18 6 16 18 1 17 17
6 9 3 10 9 1 10 1 5

output

Copy

0 7 13 18 24 35 36 37 40 45

input

Copy

10 1
3 2 3 1 3 3 1 4 1
1 2 3 4 4 1 2 1 3

output

Copy

0 2 4 7 8 11 13 14 16 17

题解:

一道dp题,只要注意有先坐电梯再走楼梯再坐电梯的操作(虽然俺也不知道为什么有这样神奇的操作,但的确有这样的最优解)

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,m,s;
long long a[1000001],b[1000001],dp[1000001][2];
int main()
{cin>>n>>m;s=0;for(int i=1;i<n;i++){cin>>a[i];}for(int i=1;i<n;i++){cin>>b[i];}cout<<0;dp[0][0]=0;dp[0][1]=m;for(int i=1;i<n;i++){dp[i][0]=min(dp[i-1][0]+a[i],dp[i-1][1]+b[i]);dp[i][1]=min(dp[i-1][0]+a[i]+m,dp[i-1][1]+b[i]);cout<<" "<<min(dp[i][0],dp[i][1]);}
} 

E. By Elevator or Stairs?相关推荐

  1. By Elevator or Stairs? CodeForces - 1249E(动态规划)

    题意 n层楼,a[i] (0<i<n)表示从 i 楼到 i + 1 楼走楼梯的时间,b[i] (0<i<n)表示从 i 楼到 i + 1 楼乘电梯的时间,其中每一次乘电梯需要等 ...

  2. E:By Elevator or Stairs? CF595 DP最短路

    题目链接 比赛的时候一看,这不是最短路吗,然后敲了一个最短路. 然后比赛完发现大家基本都写的dp,我真是个憨憨,dp3行 最短路就建个简单的图,dp就是从上一维转化过来就是了 优秀的dp: //#pr ...

  3. BUAAOO P5-P7 Elevator Simulation

    目录 Abstract Introduction Topic Request Elevator Analysis Reading Requests Coordinating Scheduling an ...

  4. Cllimbing Stairs [LeetCode 70]

    1- 问题描述 You are climbing a stair case. It takes n steps to reach to the top. Each time you can eithe ...

  5. XTUOJ 1206 Dormitory's Elevator

    Dormitory's Elevator Time Limit : 1000 MS   Memory Limit : 65536 KB Problem Description The new dorm ...

  6. 一个IO的传奇一生(8) -- elevator子系统

    Elevator子系统介绍 Elevator子系统是IO 路径上非常重要的组成部分,前面已经分析过,elevator中实现了多种类型的调度器,用于满足不同应用的需求.那么,从整个IO路径的角度来看,e ...

  7. PAT甲级1008 Elevator:[C++题解]模拟

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析:统计上升次数.下降次数:停留次数就是n.然后算数即可. ac代码 #include<bits/stdc++.h> usin ...

  8. XTU Dormitory's Elevator(动态规划)

    Dormitory's Elevator Accepted : 70   Submit : 394 Time Limit : 1000 MS   Memory Limit : 65536 KB Pro ...

  9. 70. Climbing Stairs

    70. Climbing Stairs 1. 题目 You are climbing a stair case. It takes n steps to reach to the top. Each ...

最新文章

  1. pythonsvc_sklearn-SVC实现与类参数详解
  2. 安全使用网上银行 享受在线购物时尚生活
  3. 【今日CV 计算机视觉论文速览 第125期】Wed, 5 Jun 2019
  4. [笔记]远程终端API,Terminal Services Administration
  5. 录音机 在launcher中显示_「 腾讯 微信事业部 社招二面」——一个APP从启动到主页面显示经历了哪些过程?...
  6. Command line is too long. Shorten command line for Application---微服务升级_SpringCloud Alibaba工作笔记0067
  7. oracle全角括号忽略,Oracle中SQL查询语句日文不区分全角/半角
  8. cxf-2.4.1 webservice客户端调用代码
  9. Android内核开发:在源码树中添加新的app应用
  10. 利用神经网络内部表征可视化class-specific image regions区域
  11. Jupyter Notebook 添加说明表格Cell
  12. eXeScope 提取.exe/.dll中的图片资源
  13. [转]抢先Mark!微信公众平台开发进阶篇资源集锦
  14. Wiki系列(一):Wiki系统选择
  15. 通过抓包来看http三次握手的具体细节
  16. 从专业角度分析国内创客教育发展
  17. android 拦截耳机按键,Android耳机监测以及耳机按键监测
  18. 中鑫优配周末重磅利好 周一大盘如何走
  19. python中hub_如何用Python实现hub
  20. 勇敢跨越,从0到1开发一个属于自己的App

热门文章

  1. chrome调试js
  2. 【技术】python 爬虫一招解决SSl 报错SSLError
  3. 图像分类篇——AlexNet详解
  4. 【vue】vue安装卡住/报错
  5. 创建K26 SOM最小系统
  6. 【CSS】如何让文字与input垂直居中对齐
  7. 世界上还有人以“厕所”为姓,都知道是哪国人
  8. python xlwt 用法演示
  9. Facebook灰度手势识别论文笔记
  10. KendoUI组件基础(上)