Make an X (Hard)
Time limit1sMemory limit1024 MB
- Level
Not classified yet
- Solved
- No attempts yet
Problem
This problem is the same as Make an X except for the constraint on .
pushpins are stuck on a board. Each pushpin is a very small point, and the board is modeled as an infinite coordinate plane. Phoenix, who likes the letter X, wants to remove some of the pushpins so that the remaining ones form an X shape. An X shape is defined as follows.
- There is a center pushpin that satisfies the conditions below.
- No other pushpin shares an coordinate or a coordinate with .
- Treating as the origin, no two pushpins in the same quadrant share an coordinate or a coordinate, and each quadrant contains at least one pushpin.
- Treating as the origin, sort the pushpins in quadrants 1 and 3 by coordinate. Their coordinates increase.
- Treating as the origin, sort the pushpins in quadrants 2 and 4 by coordinate. Their coordinates decrease.
Given the positions of the pushpins, find the minimum number of pushpins to remove so that the remaining pushpins form an X shape.
Input
The first line contains the number of pushpins . ()
Each of the next lines contains the position , of the -th pushpin. ()
All coordinates are integers, and no two pushpins share the same coordinates.
Output
Print the minimum number of pushpins to remove so that the remaining pushpins form an X shape. If the given pushpins cannot form an X shape, print -1.