codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

500A.md (2494B)


      1 Source: https://codeforces.com/problemset/problem/500/A
      2 
      3 A. New Year Transportation
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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.
     22 
     23 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 *a*1, *a*2, ..., *a**n* - 1. For every integer *i* where 1 ≤ *i* ≤ *n* - 1 the condition 1 ≤ *a**i* ≤ *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* + *a**i*), and one can travel from cell *i* to cell (*i* + *a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i* + *a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1 ≤ *a**i* ≤ *n* - *i* one can't leave the Line World using portals.
     24 
     25 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 *t* by only using the construted transportation system.
     26 
     27 Input
     28 
     29 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.
     30 
     31 The second line contains *n* - 1 space-separated integers *a*1, *a*2, ..., *a**n* - 1 (1 ≤ *a**i* ≤ *n* - *i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
     32 
     33 Output
     34 
     35 If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 8 4  
     43 1 2 1 2 1 2 1
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 YES
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 8 5  
     56 1 2 1 2 1 1 1
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 NO
     63 ```
     64 
     65 Note
     66 
     67 In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
     68 
     69 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.