Problem description

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.

解题思路:从cell1即f[1]出发,只要当前f[i]能到达,f[i+a[i]]就能到达,最后查看f[t]是否为true(表示已经访问过),是的话为"YES",否则为"NO"。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
const int maxn=3e4+;
int n,t,a[maxn];bool f[maxn];
int main(){
cin>>n>>t;
memset(f,false,sizeof(f));f[]=true;
for(int i=;i<n;++i)cin>>a[i];
for(int i=;i<n;++i)
if(f[i])f[i+a[i]]=true;
if(f[t])cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return ;
}

S - New Year Transportation的更多相关文章

  1. POJ 1797 Heavy Transportation(最大生成树/最短路变形)

    传送门 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 31882   Accept ...

  2. 【HDU 4940】Destroy Transportation system(无源无汇带上下界可行流)

    Description Tom is a commander, his task is destroying his enemy’s transportation system. Let’s repr ...

  3. Heavy Transportation(最短路 + dp)

    Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64 ...

  4. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  5. poj 1797 Heavy Transportation(最短路径Dijkdtra)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 26968   Accepted: ...

  6. POJ 1797 Heavy Transportation

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  7. uva301 - Transportation

      Transportation Ruratania is just entering capitalism and is establishing new enterprising activiti ...

  8. POJ 1797 Heavy Transportation (最短路)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 22440   Accepted:  ...

  9. POJ 1797 Heavy Transportation (dijkstra 最小边最大)

    Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...

  10. TOJ3744(Transportation Costs)

    Transportation Costs   Time Limit(Common/Java):2000MS/6000MS     Memory Limit:65536KByte Total Submi ...

随机推荐

  1. jdbcUrl is required with driverClassName错误解决

    jdbcUrl is required with driverClassName springboot2.0配置多数据源: spring.datasource.primary.url=jdbc:mys ...

  2. JAVA学习总结-常用数据结构

    java中集合框架其实就是数据结构的实现的封装; 参考资料:任小龙教学视频 1,什么是数据结构? 数据结构是计算机存储,组织数据的方式; 数据结构是指相互之间存在一种或多种特定关系的数据元素的集合; ...

  3. bytes类型和python中编码的转换方法

    一.bytes类型 bytes类型是指一堆字节的集合,在python中以b开头的字符串都是bytes类型.例如: >>> a = "中国" >>> ...

  4. LOJ 6278 数列分块入门2

    [题解] 分块.块内排序.块内二分出第一个大于等于c的数. #include<cstdio> #include<algorithm> #include<cmath> ...

  5. LeetCode 712. Minimum ASCII Delete Sum for Two Strings

    Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal. ...

  6. spring boot 中访问 REST 接口

    RestTemplate restTemplate = new RestTemplate(); Object result = restTemplate.getForObject("http ...

  7. Monthly Expense POJ 二分

    Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...

  8. P1331 海战 洛谷

    题目描述 在峰会期间,武装部队得处于高度戒备.警察将监视每一条大街,军队将保卫建筑物,领空将布满了F-2003飞机.此外,巡洋船只和舰队将被派去保护海岸线.不幸的是因为种种原因,国防海军部仅有很少的几 ...

  9. 最小堆的两种实现及其STL代码

    #include<cstdio> #include<iostream> #include<algorithm> #include<vector> boo ...

  10. PHP array_flip()

    定义和用法 array_flip() 函数返回一个反转后的数组,如果同一值出现了多次,则最后一个键名将作为它的值,所有其他的键名都将丢失. 如果原数组中的值的数据类型不是字符串或整数,函数将报错. 语 ...