luogu#P16330. Just Because!
Just Because!
Problem Description
You are given trees. The -th tree is located at position and has height . It is guaranteed that the sequence is strictly increasing.
There are queries. For the -th query, only the subarray is kept. You need to choose as many trees as possible such that there exists a way to cut them down so that no tree trunk hits another trunk.
Formally, let $S=\{s_1,s_2,\dots,s_k\}\subseteq\{l_i,l_i+1,\dots,r_i\}$ with .
The requirement is that for every , we have $p_{s_j}+h_{s_j}<p_{s_{j+1}} \lor p_{s_j}-h_{s_j}>p_{s_{j-1}}.$
Find the maximum possible value of .
Note that you don't actually cut any trees, and when you compute the answer, the trees' positions and heights remain unchanged.
Input Format
The first line contains two positive integers .
The second line contains positive integers, denoting .
The third line contains a strictly increasing sequence of positive integers .
The next lines each contain two positive integers , describing the query interval.
Output Format
Output lines. Each line should contain one integer, the answer for the corresponding query.
5 3
3 5 8 9 10
2 7 5 9 9
4 5
1 5
1 4
2
2
2
17 16
7 8 15 20 24 27 30 37 40 44 48 52 56 60 64 68 72
5 1 1 4 1 2 1 2 3 2 2 5 7 4 7 6 7
2 12
10 12
4 14
4 8
3 3
3 16
3 13
1 16
3 15
15 16
1 15
3 16
2 14
5 16
4 17
4 14
11
3
10
5
1
12
10
14
12
2
14
12
12
10
12
10
Hint
Constraints
For all test cases, , , and . For all , it is guaranteed that .
| Subtask | Special Property | Score | ||
|---|---|---|---|---|
| None | ||||
| Yes | ||||
| None | ||||
- Special property: For all , it is guaranteed that .