Secure Prison (Basic)
InterviewTime limit2sMemory limit1024 MB
Given n room types where none fits inside another, for each type i find the least cost of enlarging some other type j so that type i fits inside it.
- Level
Medium6 of 10
- Topics
- Sorting, Binary search, Segment tree
- Solved
- No attempts yet
Problem
Eddie and Venom's troubles begin 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 experience, the new warden of San Quentin decided that the restored prison will include a maximum security cell, a room placed inside another room. San Francisco law allows rooms of exactly one of types. The -th type is a rectangle with side from west to east and side from north to south (but not the other way around). A room can be placed inside a room if and only if and . For safety, the outer and inner rooms must be of different types.
Unfortunately, none of the allowed room types fits inside another. For example, no two rooms of sizes , , and can be placed one inside the other. So the warden may choose any type for the inner room and bend the rules a little for the outer room. He may choose any type for the outer room and expand the room to (that is, choose any , ), paying the city government money, so that the room of type fits inside it.
The warden wants to spend as little money as possible without risking safety. So before making the final choice, he wants to know the minimum amount he must pay the government for each from to , if the inner room is of type .
Input
The first line contains a single integer , the number of room types officially allowed in San Francisco (). The -th of the next lines contains integers and separated by a space, the dimensions of the -th room type (). It is guaranteed that no two different room types can be placed one inside the other.
Output
Print integers separated by spaces. The -th integer is the minimum amount of money needed to build a maximum security cell with the inner room of type .