#P4269. Snow Boots

    ID: 17515 Type: Default 1000ms 256MiB

Snow Boots

Snow Boots

It is winter on the farm, and snow covers the path from the farmhouse to the barn. There are \(N\) tiles, numbered \(1 \dots N\), where tile \(i\) is covered in \(f_i\) feet of snow. Farmer John has \(B\) pairs of boots, each described by two integers \(s_i\) and \(d_i\): boot \(i\) can be used on tiles with at most \(s_i\) feet of snow and allows him to take steps of at most \(d_i\) tiles forward.

Both tile 1 (at the farmhouse) and tile \(N\) (at the barn) are sheltered (i.e. have no snow). For each pair of boots, determine whether Farmer John can use that single pair to traverse from tile 1 to tile \(N\) by choosing a valid sequence of steps. In a step, he may move forward any number of tiles between 1 and \(d_i\) as long as the destination tile has snow depth \(\le s_i\). Output YES if he can reach the barn, and NO otherwise.

inputFormat

The first line contains two integers \(N\) and \(B\) separated by a space, representing the number of tiles and the number of boot pairs, respectively.

The second line contains \(N\) integers \(f_1, f_2, \dots, f_N\) where \(f_i\) indicates the snow depth on tile \(i\). Note that \(f_1 = f_N = 0\).

The next \(B\) lines each contain two integers \(s_i\) and \(d_i\) for \(i = 1 \dots B\), representing the maximum snow depth that boot \(i\) can tolerate and the maximum forward step length allowed, respectively.

outputFormat

Output \(B\) lines. The \(i\)th line should contain YES if boot pair \(i\) can be used to traverse from tile 1 to tile \(N\), or NO otherwise.

sample

5 3
0 2 4 1 0
3 2
4 3
1 1
YES

YES NO

</p>