New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.

So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of n - 1 positive integers a1, a2, ..., an - 1. For every integer i where 1 ≤ i ≤ n - 1 the condition 1 ≤ ai ≤ n - i holds. Next, he made n - 1 portals, numbered by integers from 1 to n - 1. The i-th (1 ≤ i ≤ n - 1) portal connects cell i and cell (i + ai), and one can travel from cell i to cell (i + ai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (i + ai) to cell i using the i-th portal. It is easy to see that because of condition 1 ≤ ai ≤ n - i one can't leave the Line World using portals.

Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell tby only using the construted transportation system.

Input

The first line contains two space-separated integers n (3 ≤ n ≤ 3 × 104) and t (2 ≤ t ≤ n) — the number of cells, and the index of the cell which I want to go to.

The second line contains n - 1 space-separated integers a1, a2, ..., an - 1 (1 ≤ ai ≤ n - i). It is guaranteed, that using the given transportation system, one cannot leave the Line World.

Output

If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO".

Examples

Input

8 4
1 2 1 2 1 2 1

Output

YES

Input

8 5
1 2 1 2 1 1 1

Output

NO

Note

In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.

In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.

题解:模拟更新可以到达的位置,然后加上该位置下标的值

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; int main() {
int n,m;
cin>>n>>m;
int a[30005];
for(int t=1; t<=n-1; t++) {
scanf("%d",&a[t]);
}
int flag=0;
for(int t=1; t<n;) {
t=t+a[t];
//cout<<t<<endl;
if(t==m) {
flag=1;
}
} if(flag==1) {
cout<<"YES"<<endl;
} else {
cout<<"NO"<<endl;
}
return 0;
}

CodeForces - 500A-New Year Transportation(模拟)的更多相关文章

  1. codeforces 500A. New Year Transportation

    题目链接:http://codeforces.com/problemset/problem/500/A 题目意思:给出 n-1 个 cell,每个 cell 有一个值 ai,表示在这个编号为 i 的 ...

  2. Codeforces 500A - New Year Transportation【DFS】

    题意:给出n个数,终点t 从第i点能够跳到i+a[i],问能否到达终点 #include<iostream> #include<cstdio> #include<cstr ...

  3. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  4. Codeforces 747C:Servers(模拟)

    http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...

  5. Codeforces 740A. Alyona and copybooks 模拟

    A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...

  6. Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. CodeForces 670 A. Holidays(模拟)

    Description On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Ma ...

  8. Codeforces 280D k-Maximum Subsequence Sum [模拟费用流,线段树]

    洛谷 Codeforces bzoj1,bzoj2 这可真是一道n倍经验题呢-- 思路 我首先想到了DP,然后矩阵,然后线段树,然后T飞-- 搜了题解之后发现是模拟费用流. 直接维护选k个子段时的最优 ...

  9. Codeforces 1090B - LaTeX Expert - [字符串模拟][2018-2019 Russia Open High School Programming Contest Problem B]

    题目链接:https://codeforces.com/contest/1090/problem/B Examplesstandard input The most famous characters ...

  10. CodeForces - 586C Gennady the Dentist 模拟(数学建模的感觉)

    http://codeforces.com/problemset/problem/586/C 题意:1~n个孩子排成一排看病.有这么一个模型:孩子听到前面的哭声自信心就会减弱:第i个孩子看病时会发出v ...

随机推荐

  1. BZOJ 1207 [HNOI2004]打鼹鼠:dp【类似最长上升子序列】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1207 题意: 有一个n*n的网格,接下来一段时间内会有m只鼹鼠出现. 第i只鼹鼠会在tim ...

  2. 分享知识-快乐自己:Struts2中 获取 Request和Session

    目录结构: POM: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEnco ...

  3. Java内部类复习

    package com.t_06; import org.junit.Test; import com.t_06.StaticClass.StaticInnerClass; /** * 一个类的定义放 ...

  4. HTml js 生成图片

    <script type="text/javascript"> function $(id) { return document.getElementById(id); ...

  5. mac hosts

    1 在命令行中输入:sudo vim /etc/hosts. 2 输入开机密码,就可打开文件.按下键盘i,对文件进入可编辑状态. 3 修改完,先按esc退出编辑模式,之后,按shift+:,再按wq来 ...

  6. 更换mysql数据目录后出现 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 的解决办法

    服务器上的mysql默认数据目录为/var/lib/mysql/,同时服务器的/空间不是很大,而近期又有大量的日志需要导入进行分析,时常搞得/的空间捉襟见肘,晚上一狠心就想把mysql的数据目录转移到 ...

  7. AR/VR-AR:AR

    ylbtech-AR/VR-AR:AR 增强现实技术(Augmented Reality,简称 AR),是一种实时地计算摄影机影像的位置及角度并加上相应图像.视频.3D模型的技术,这种技术的目标是在屏 ...

  8. 【win10激活问题】 从【win10专业工作站版】转为 数字许可证的【win10专业版】

    今天安装了 win10 1903 (10.0.18362 暂缺 Build 18362) 安装时 选的 是[win10 专业工作站版] 却无法激活, (因为当初是从win7升级上win10的,只有关联 ...

  9. 隐藏时间表ribbon按钮

    Ribbon.ContextualTabs.Timesheet.Home.Share;Ribbon.ContextualTabs.Timesheet.Home.ShowHide;Ribbon.Cont ...

  10. 【246】◀▶IEW-Unit11

    Unit 11 Transport 1. Model1题目分析 Some countries attempt to solve the problem of traffic congestion by ...