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

转载于:https://www.cnblogs.com/Staceyacm/p/10781884.html

CodeForces - 500A-New Year Transportation(模拟)相关推荐

  1. acm寒假特辑1月24日 HDU - 2191(背包)/CodeForces - 500A

    A - 1 CodeForces - 500A (签到) New Year is coming in Line World! In this world, there are n cells numb ...

  2. CodeForces 1463 C. Busy Robot 模拟

    CodeForces 1463 C. Busy Robot 模拟 题目大意: 有一个一维坐标轴,在最初时刻有个机器人位于坐标 0 0 0 位置,有 n n n 个命令,对于每一个命令在 t i t_i ...

  3. BZOJ 3836 Codeforces 280D k-Maximum Subsequence Sum (模拟费用流、线段树)

    题目链接 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.php?id=3836 (Codeforces) http://codeforces.com ...

  4. 【CodeForces Round #550】A-F | 模拟 | 贪心 | 高精 | BFS | 二分图 | E

    今年怎么没有愚人节比赛了   CF你看看人家洛谷   唉鸭原来那边还没到愚人节呢- 愚人节比赛还是有的,在今晚 qwq [CodeForces 1144   A-F] Tags:模拟 贪心 BFS 高 ...

  5. CodeForces - 1328F Make k Equal(模拟)

    题目链接:点击查看 题目大意:给出一个数列 a ,现在有两种操作: 找到一个最小值,使其值加一 找到一个最大值,使其值减一 注意这里找到一个最值进行的操作,是针对最值不唯一的情况,题目问至少需要进行多 ...

  6. CodeForces - 1321C Remove Adjacent(贪心+模拟)

    题目链接:点击查看 题目大意:给出一个长度不超过100且只包含小写字母的字符串,现在规定,如果某个位置 i 的相邻位置存在着当前位置所代表字母的前一个字母,即 i - 1 和 i + 1 中存在着 a ...

  7. CodeForces - 1208E Let Them Slide(模拟+multiset)

    题目链接:点击查看 题目大意:给出n个数列,每行放一个,现在指定一个宽度w,满足w不小于n个数列中最长的那个数列的长度,现在可以将n个数列都放入到一个n*w的矩形之中,每个数列可以在各自的行内左右移动 ...

  8. CodeForces - 546C Soldier and Cards(模拟)

    题目链接:点击查看 题目大意:两个人在玩游戏,初始时两个人分别有一定数量的牌,牌面的大小一定是互不相同的,游戏规则如下: 每次两个人同时从自己牌堆的最顶端取出一张牌,我们可以记做a和b,比较一下其大小 ...

  9. CodeForces - 224C. Bracket Sequence (栈模拟)简单做法

    A bracket sequence is a string, containing only characters "(", ")", "[&quo ...

  10. 【CodeForces - 298B 】Sail (模拟,题意)

    题干: The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boa ...

最新文章

  1. apache 重定向tomcat端口_Tomcat
  2. python numpy.array 与list类似,不同点:前者区分元素不用逗号,中间用空格,矩阵用[]代表行向量,两个行向量中间仍无逗号;  而list区分元素用逗号
  3. 使用Emit的TypeBUilder动态创建接口程序集的性能报告。
  4. 考察大新和南宁农业产业园 农业大健康·李喜贵:赋能乡村振兴
  5. win7下设置无线上网
  6. Asp.Net Core中Session使用
  7. 还在发愁linux命令记不住吗?神器来了!
  8. vue cli3.0创项目报错‘This may cause things to work incorrectly. Make sure to use the same version for b’
  9. Robust Regression_2016_鲁棒回归推导
  10. Git - git tag - 查看当前分支 tag 版本说明
  11. 阿里云2017财年:营收66.63亿 同比增长121%
  12. 移动硬盘参数错误要怎么办啊
  13. nagios监控安装配置
  14. Certbot的使用
  15. macos最新版本是什么_macOS的最新版本是什么?
  16. malloc与free函数原型
  17. 礼物说仿写项目iOS源码
  18. 学python对数学要求吗_python 学习和数学知识 - 文章分类 - 风中小郎君 - 博客园...
  19. 【2022新书】有趣的数据结构
  20. 字母数字混合提取数字C语言,如何将包含汉字,字母和数字的混合字符串转换为纯数字...

热门文章

  1. Linux 命令之 apt -- Debian Linux 新一代的软件包管理工具
  2. 浅析文件传输协议 (ftp) 的工作原理
  3. Thread 线程同步、线程状态
  4. 内部收益率irr_介绍一个神器,内部收益率IRR
  5. python中常用的方法
  6. python3.7打包exe坑_[求助]入坑学习python 需要装pyinstaller打包成exe
  7. C语言标识符、关键字和注释
  8. 如何用python实现地图定位_基于 PyQt5 实现地图中定位相片拍摄位置
  9. 多模光纤收发器的应用领域及适用领域
  10. 飞畅科技-工业交换机电源故障初探