All Tracks Algorithms Dynamic Programming Introduction to Dynamic Programming 1 Problem

Tower of Hanoi
/

Algorithms, Dynamic Programming

Problem
Editorial
Analytics

Bob and Alice like to play the game tower of Hanoi. One day Alice challenges Bob to build the tallest tower from a set of disks of different height and radius. The tower of Hanoi can be built by stacking disks on top of each other. In order to put disk A on top of disk B, the radius and height of A must be strictly smaller than those of B. Help Bob to win the challenge.

Input:
First line of input contains number of test cases T.
First line of each test case contains value of N, the number of disks. The next N lines contains two positive integer number Ri and Hi corresponding to the radius and height of ith Disk respectively.

Output:
For each test case print the maximum height of the tower possible.

Constraints:
1<=T<=10
1<=N<=200
1<=Ri, Hi<=10^9

SAMPLE INPUT
2
3
4 3
1 4
3 2
5
5 6
4 3
1 2
7 5
3 4

SAMPLE OUTPUT
5
12

Time Limit: 5.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB

Best Submission

Similar Problems

Contributors

This Problem was Asked in

Initializing Code Editor...
Notifications
View All Notifications

?