#P10845. Tulip Bouquet
Tulip Bouquet
Tulip Bouquet
Lieke, inspired by a visit to one of the world's largest gardens, decided to create a beautiful bouquet using wild roadside tulips. However, she must comply with the Dutch Tulip Protection Act. There are N tulips arranged along a road from left to right, numbered from 0 to N-1. Each tulip i is assigned two integers \(l_i\) and \(r_i\). If tulip i is included in the bouquet, then the li tulips immediately to its left and the ri tulips immediately to its right (even if fewer exist) cannot be included in the bouquet.
In other words, if you select a tulip i, then for the chosen set of indices \(i_1 < i_2 < \cdots < i_k\), for every consecutive pair \(i_j\) and \(i_{j+1}\) the following conditions must hold:
- \(i_{j+1} \ge i_j + r_{i_j} + 1\) (tulip i_j forbids the next \(r_{i_j}\) tulips) and
- \(i_{j+1} \ge i_j + l_{i_{j+1}} + 1\) (tulip i_{j+1}'s left neighbors must be clear).
Your task is to help Lieke by computing the maximum number of tulips that she can collect to form a legal bouquet.
inputFormat
The first line contains a single integer N (the number of tulips).
Each of the following N lines contains two integers li and ri, describing the exclusion counts for the tulip with index i.
outputFormat
Print a single integer denoting the maximum number of tulips that can be collected while obeying the protection law.
sample
5
0 0
0 0
0 0
0 0
0 0
5
</p>