406630: GYM102465 F Paris by Night

Memory Limit:256 MB Time Limit:15 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Paris by Nighttime limit per test15 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
During her trip to Paris for SWERC, Morgane graded every monument she visited. On this last night of the week, she plans to go in some hot-air balloon and take two $$$180^\circ$$$ panoramic photographs of the city, thereby getting a perfect $$$360^\circ$$$ view. She would like both photographs to be approximately as nice as each other.

Hence, she will proceed as follows. She chooses two monuments, that we will call the boundary monuments, and asks the balloon pilot to go between these monuments. From there, she takes two $$$180^\circ$$$ pictures: each picture shows one side of Paris, both sides being delimited by the two boundary monuments. Each picture receives a grade, which is the sum of the grades of the monuments that it shows, including the boundary monuments on both pictures. Finally, if the pictures have grades A and B, the goal of Morgane is to minimize the difference between A and B (in absolute value).

The visibility from the balloon is such that all monuments can be seen in either of the two photographs.

You must assist Morgane in choosing appropriate boundary monuments. In order to do this, you are given a list of the monuments. For every monument visited by Morgane, this list contains a line which indicates the Cartesian coordinates of the monument location, along with the monument's grade. You should give the minimal possible difference, among all pairs of pictures that Morgane may take, between the grades of the two pictures.

Important Note

Morgane was so precise at locating every monument that no three monuments are on a same straight line.

Input

The input comprises several lines, each consisting of integers separated with single spaces:

  • the first line contains the number N of monuments;
  • each of the N next lines contains three integers associated with each monument: the X coordinate, the Y coordinate and the grade G of the monument represented on that line.

Limits

  • $$$2 \le N \le 4000$$$;
  • $$$0 \le X,\ Y \le 1000000000$$$ and $$$1 \le G \le 1000000000$$$.
Output

The output should consist of a single line, whose content is an integer, the minimal difference (in absolute value) between the grades of a pair of photographs that Morgane may take.

ExampleInput
8
0 0 10
1 1 2
2 1 3
3 2 7
2 3 8
5 2 5
1 5 12
4 5 14
Output
2

加入题单

上一题 下一题 算法标签: