http://codeforces.com/problemset/problem/1249/E

E. By Elevator or Stairs?
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are planning to buy an apartment in a n

-floor building. The floors are numbered from 1 to n

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:

  • ai

for all i from 1 to n−1 be the time required to go from the i-th floor to the (i+1)-th one (and from the (i+1)-th to the i

  • -th as well) using the stairs;
  • bi

for all i from 1 to n−1 be the time required to go from the i-th floor to the (i+1)-th one (and from the (i+1)-th to the i-th as well) using the elevator, also there is a value c

  • — 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 x

to any floor y (x≠y

) in two different ways:

  • If you are using the stairs, just sum up the corresponding values of ai

. Formally, it will take ∑i=min(x,y)max(x,y)−1ai

  • time units.
  • If you are using the elevator, just sum up c

and the corresponding values of bi. Formally, it will take c+∑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 i

to determine the minimum total time it takes to reach the i-th floor from the 1

-st (bottom) floor.

Input

The first line of the input contains two integers n

and c (2≤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−1

integers a1,a2,…,an−1 (1≤ai≤1000), where ai is the time required to go from the i-th floor to the (i+1)-th one (and from the (i+1)-th to the i

-th as well) using the stairs.

The third line of the input contains n−1

integers b1,b2,…,bn−1 (1≤bi≤1000), where bi is the time required to go from the i-th floor to the (i+1)-th one (and from the (i+1)-th to the i

-th as well) using the elevator.

Output

Print n

integers t1,t2,…,tn, where ti is the minimum total time to reach the i

-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

题意:有n楼,给你1到2,2到3....n-1到n楼的爬楼梯时间和坐电梯时间。从楼梯去坐电梯需要等电梯开门的时间c。问每一楼到一楼的最短时间。

解法:考虑四个转移状态:从楼梯到楼梯,从楼梯到电梯,从电梯到楼梯,从电梯到电梯。

//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdio.h>
#include <queue>
#include <stack>;
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define mod 998244353
#define PI acos(-1)
using namespace std;
typedef long long ll ;
ll a[] , b[];
ll dp[][]; int main()
{
ll n , c ;
while(~scanf("%lld%lld" , &n , &c))
{
for(int i = ; i <= n ; i++)
{
scanf("%lld" , &a[i]);
}
for(int i = ; i <= n ; i++)
{
scanf("%lld" , &b[i]);
}
memset(dp , INF , sizeof(dp));
dp[][] = c ;
dp[][] = ;
for(int i = ; i <= n ; i++)
{
dp[i][] = min(dp[i][] , dp[i-][]+a[i]);//电梯到楼梯
dp[i][] = min(dp[i][] , dp[i-][]+a[i]);//楼梯到楼梯
dp[i][] = min(dp[i][] , dp[i-][]+b[i]);//电梯到电梯
dp[i][] = min(dp[i][] , dp[i-][]+b[i]+c);//楼梯到电梯
} for(int i = ; i < n ; i++)
cout << min(dp[i][] , dp[i][]) << " " ;
cout << min(dp[n][] , dp[n][]) << endl ;
} return ;
}

dp(电梯与楼梯)的更多相关文章

  1. CodeForces - 1249E 楼梯和电梯

    题意:第一行输入n和c,表示有n层楼,电梯来到需要时间c 输入两行数,每行n-1个,表示从一楼到二楼,二楼到三楼.....n-1楼到n楼,a[ ] 走楼梯和 b[ ] 乘电梯花费的时间 思路:动态规划 ...

  2. CodeForces1249E-By Elevator or Stairs?-好理解自己想不出来的dp

    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≤1 ...

  3. 兑换零钱-(dp)

    https://ac.nowcoder.com/acm/contest/910/B 本以为是组合数,没想到是dp求解,变成水题了,让我想起了第一次见到dp的爬楼梯,可以走一步和走两步,走40步,这里相 ...

  4. CodeForces round 967 div2 题解(A~E)

    本来准备比完赛就写题解的, 但是一拖拖了一星期, 唉 最后一题没搞懂怎么做,恳请大神指教 欢迎大家在评论区提问. A Mind the Gap 稳定版题面 https://cn.vjudge.net/ ...

  5. codeforces966 A

    这题主要就是考虑y1两侧的最近的电梯和楼梯 当时主要是考虑  如果电梯在y1和y2中间的话   那么直接做电梯就是最优解   如果在y2右边就用abs去算 然后发现其实只考虑 y1的左右两边的电梯和楼 ...

  6. leetcode算法总结

    算法思想 二分查找 贪心思想 双指针 排序 快速选择 堆排序 桶排序 搜索 BFS DFS Backtracking 分治 动态规划 分割整数 矩阵路径 斐波那契数列 最长递增子序列 最长公共子系列 ...

  7. 机器人自主移动的秘密,从SLAM技术说起(一)

    博客转载自:https://www.leiphone.com/news/201609/c35bn1M9kgVaCCef.html 雷锋网(公众号:雷锋网)按:本文作者SLAMTEC(思岚科技公号sla ...

  8. 2.8/4/6/8mm/12mm焦距的镜头分别能监控多大范围?

    2.8/4/6/8mm/12mm焦距的镜头分别能监控多大范围? 相关介绍 一.焦距和监控距离的关系 我司IPC镜头焦距有2.8/4mm/6mm/8mm等多种选择,可以满足室内外各种环境的拍摄需求.IP ...

  9. Leedcode算法专题训练(动态规划)

    递归和动态规划都是将原问题拆成多个子问题然后求解,他们之间最本质的区别是,动态规划保存了子问题的解,避免重复计算. 斐波那契数列 1. 爬楼梯 70. Climbing Stairs (Easy) L ...

随机推荐

  1. 第一次接触oracle

    登录 SQLPLUS cmd sqlplus [用户名]/[密码][@数据库] [参数] sqlplus sys/orcl as sysdba -- 登录 sys 用户,必须指定 sysdba 或 s ...

  2. LOJ#2330 榕树之心 树形dp

    瞎扯 这个题和\(\mathsf{ISIJ2019 Au}\)神仙学弟\(\mathsf{\color{red}c}\mathsf{hangruinian2020}\)争辩了半个多小时. 概括一下就是 ...

  3. 两个jquery编写插件实例

    (1) 封装基于jq弹窗插件   相信码友们对于$.fn.extexd();$.extend()以及$.fn.custom和$.custom都有一定的了解:我阐述一下我自己对于$.fn.custom和 ...

  4. lua脚本入门

    在网上下载一些工程,里边常常存在.lua .sh .in .cmake .bat等文件 今天专门查了一下相关文件的作用 .sh 通常是linux.unix系统下的脚本文件(文本文件),用于调用默认的s ...

  5. [CF342C]Cupboard and Balloons 题解

    前言 博主太弱了 题解 这道题目是一个简单的贪心. 首先毋庸置疑,柜子的下半部分是要放满的. 于是我们很容易想到,分以下三种情况考虑: \[\small\text{请不要盗图,如需使用联系博主}\] ...

  6. 主流Linux可视化运维面板&安装包

    一.AMH面板 1.官方网站 官方网站:http://amh.sh 2.面板介绍 截止到AMH4. 2 版本都是提供免费安装的,后来从5. 0 开始提供付费安装,可以理解开发者的盈利问题,毕竟提供免费 ...

  7. WinSetupFromUSB - 超简单制作多合一系统安装启动U盘的工具 (支持Win/PE/Linux启动盘)

    很多同学都喜欢将电脑凌乱不堪的系统彻底重装以获得一个"全新的开始",但你会发现如今很多电脑都已经没有光驱了,因此制作一个U盘版的系统安装启动盘备用是非常必要的. 我们之前推荐过 I ...

  8. java 中 进程和线程的区别

    目录 什么是进程?什么是线程? 为什么要有线程? 进程与线程的区别? 进程与线程的选择取决条件? 什么是进程?什么是线程?进程:进程是并发执行程序在执行过程中资源分配和管理的基本单位(资源分配的最小单 ...

  9. this._super()

    https://learn.jquery.com/jquery-ui/widget-factory/extending-widgets/ https://api.jqueryui.com/jquery ...

  10. Oracle10g 64位 在Windows 2008 Server R2 中的安装 DBconsole无法启动

    致谢!本文参考http://www.cnblogs.com/leiOOlei/archive/2013/08/19/3268239.html 背景: 操作系统Windows 2008 Server R ...