Time Limit : 1 Second
Memory Limit : 128 MB
Submission: 93
Solved: 50
Description
LL likes playing poker, especially “Play against Land Lord”. He likes consecutive cards mostly. But he wants to know how many round at least he must play to give away all his cards. To simplify the problem we need to change the rule a little.
New rule:
1.Any number of cards can be given away, as long as they are consecutive. That is to say, 1, 12, 123, 1234 are all allowed.
2.Multiple consecutive cards are forbidden. That is to say, 112233, 222333 are not allowed.
3.There are only number cards (no A, J, K, Q…) with number in range [1, 10000].
Input
The first line of input contains one integer specifying the number of test cases to follow. Each test case begins with a line containing an integer N (1 <= N <= 10000), the number of groups of cards LL have. The next N lines each describes a group using two numbers k, x, meaning that LL has k cards with number x (1 <= k, x <= 10000). It is guaranteed that the same x won’t appear twice.
Output
For each test case, output a line containing a single integer, the minimum rounds LL must play to give away all cards.
sample input
2
5
1 1
2 4
3 3
2 2
1 5
1
2 1
sample output
3
2
hint
source
Isun
Submit