Kuki's Struggle to Open a Restaurant
Time limit2sMemory limit512 MB
Place the restaurant at a point off both axes so that the gap between the largest and smallest quadrant hunger sums is as small as possible.
- Level
Medium6 of 10
- Topics
- Sorting, Prefix sum, Geometry
- Solved
- No attempts yet
Problem
Kuki plans to run a restaurant for cats at Catholic University. Kuki believes the location matters most, so Kuki is working out the best spot.
Kuki surveyed the homes of cats and recorded each home's coordinates and hunger level . No two cats live at the same coordinates.
In Kuki's country, there is a law: if a cat's home lies on a coordinate axis relative to a chosen point, the restaurant cannot be opened at that point. The restaurant may be placed at non-integer coordinates.
With the restaurant as the origin, define and as follows.
- = the sum of hunger levels of the cats in quadrant
- = (the maximum of ) minus (the minimum of )
- If no cat is in quadrant , is 0.
- If the restaurant cannot be opened at a point, is 100,000,000.

Kuki wants to open the restaurant where is smallest. Help Kuki find the minimum value of .
Input
The first line contains an integer ().
Each of the next lines contains three integers (), (), and () describing one cat.
Output
Print the minimum value of .