P1640 [SCOI2010] Continuous Attack Game
Description
lxhgww recently got hooked on a game. In the game, he owns many pieces of equipment, and each piece has $2$ attributes. The values of these attributes are numbers in $[1,10000]$. When he uses a piece of equipment, he can only use one of its attributes, and each piece of equipment can be used at most once.
At the end of the game, lxhgww encounters the final boss. This boss is peculiar: to deal damage, the attribute values used to attack must increase consecutively starting from $1$. That is, at the beginning lxhgww can only attack the boss with a piece of equipment whose attribute value is $1$, then only with a piece whose attribute value is $2$, then only with a piece whose attribute value is $3$, and so on. Now lxhgww wants to know the maximum number of consecutive attacks he can make on the boss.
Input Format
The first line contains an integer $N$, the number of types of equipment lxhgww owns. The next $N$ lines describe these $N$ types of equipment. Each line contains $2$ numbers, the $2$ attribute values of the $i$-th piece of equipment.
Output Format
Output one line with $1$ number: the maximum number of consecutive attacks lxhgww can make.
Explanation/Hint
For $30\%$ of the testdata, $N \le 10^3$.
For $100\%$ of the testdata, $N \le 10^6$.
Translated by ChatGPT 5