Stacking Boxes
View as PDF        
            Submit solution
        
    
    
    
    
    
            
    
    
    
                    
                
        
        Points:
        
                5        
    
    
        Time limit:
        1.0s
    
    
                Java
                2.0s
            
            
                Python
                1.5s
            
    
        Memory limit:
        256M
    
    
                        Author:
                        
                    
        
                    Problem type                
                
        You have  boxes with varying dimensions of 
 (width by height).
You are trying to create the tallest tower possible by stacking any combination of these boxes. In order to keep your tower balanced, you can only stack a box on top of another if its width is strictly less than the one below it. Assuming you do not place any boxes next to each other, what is the height of the tallest possible tower you can create?
Constraints
Input Specification
The first line of input contains an integer .
The next  lines of input each contain 
 space-separated integers, 
 and 
.
Output Specification
Output the height of the tallest possible tower.
The height of any given tower is the sum of the heights of its boxes.
Sample Input
3
5 2
5 3
2 10
Sample Output
13
Explanation for Sample
You can use the  box as the base of the tower and stack the 
 box on top of it.
Comments