Secure Prison
InterviewTime limit2sMemory limit1024 MB
For each room type i, find the minimum cost to enlarge another type j so that a type i room fits inside it.
- Level
Medium6 of 10
- Topics
- Sorting, Array, Implementation
- Solved
- No attempts yet
Problem
Eddie and Venom run into trouble when Carnage escapes from prison together with his host. If the prison had been more secure, nothing bad would have happened, and everyone would have lived happily ever after.
Learning from this, the new warden of San Quentin decided that the rebuilt prison will include a maximum security cell, a room placed inside another room. San Francisco law allows building rooms of exactly one of types. Type is a rectangle with side from west to east and side from north to south (and not the other way around).
Room can be placed inside room if and only if and . For safety, the outer room and the inner room must be of different types (but they do not have to be different sizes).
Of course, not every pair of rooms fits one inside the other. For example, rooms of size and cannot be placed one inside the other, because but . So if the warden wants the inner room to be of type and no other type, he is allowed to make an exception: he picks any type and expands room to (that is, picks any and ). He pays the city government money, so that a room of type fits inside it.
The warden wants to spend as little money as possible, but he does not want to risk safety. So before making the final choice, he wants to know the minimum amount he would have to pay the government if the inner room is of type , for each from to .
Input
The first line contains a single integer , the number of room types officially allowed in San Francisco ().
Each of the next lines contains two space-separated integers and , the dimensions of room type (). The sizes of the types are not guaranteed to be distinct. If two types have the same dimensions, rooms of these types can be placed inside each other.
Output
Print integers separated by spaces. The -th integer is the minimum amount of money that must be paid to build a maximum security cell whose inner room is of type .