Snow Boots#10409

Snow Boots

1 секунда
128 мегабајти
Средно

It's winter on the farm, and that means snow! There are tiles on the path from the farmhouse to the barn, conveniently numbered to , and tile is covered with f_i feet of snow.

Farmer John starts on tile and must reach tile to wake up the cows. Tile is sheltered by the farmhouse roof, and tile is sheltered by the barn roof, so neither of these tiles has any snow. But to step on any other tile, Farmer John needs to wear boots!

In his foul-weather backpack, Farmer John has pairs of boots, numbered to . Some pairs are more heavy-duty than others, and some are more agile than others. Specifically, pair allows Farmer John to step in snow at most s_i feet deep and to move forward by at most d_i tiles in a single step.

Unfortunately, the boots are packed in such a way that Farmer John can access only the topmost pair at any given time. So at any moment, Farmer John can either put on the topmost pair of boots (discarding the pair he is currently wearing) or discard the topmost pair of boots (making the next pair accessible).

Farmer John can change boots only while standing on a tile. If that tile has feet of snow, both the boots he takes off AND the boots he puts on must be able to withstand at least feet of snow. Intermediate pairs of boots that he discards without wearing do not need to satisfy this restriction.

Help Farmer John minimize waste by determining the minimum number of pairs of boots he needs to discard in order to reach the barn. Initially, Farmer John is not wearing any boots.

Влез

The first line contains two integers and b~(2 \le n, b \le 250). The second line contains integers f_1, f_2, \ldots, f_n~(0 \le f_i \le 10^9), where f_i is the depth of snow on tile . It is guaranteed that f_1 = f_n = 0.

Each of the next lines contains two integers. The (i + 2)-th line contains s_i and d_i~(0 \le s_i \le 10^9, 1 \le d_i \le n - 1) — the maximum depth of snow in which pair can step and the maximum step length for pair , respectively.

The boots are listed from top to bottom: pair is the topmost pair in Farmer John's backpack, pair is the next one, and so on.

Излез

Print one integer — the minimum number of pairs of boots Farmer John needs to discard. It is guaranteed that Farmer John can reach the barn.

Примери

Пример 1

Loading
Loading