#P10630. [JOI Open 2017] 推土机 / Bulldozer

[JOI Open 2017] 推土机 / Bulldozer

Problem Description

Translated from JOI Open 2017 T2 「ブルドーザー / Bulldozer」.

There are NN points on the plane. Point i(1iN)i\:(1\le i\le N) is located at (Xi,Yi)(X_i, Y_i), and its weight is a non-zero integer WiW_i (it may be negative).
Draw two parallel lines on the plane. The total value is defined as the sum of the weights of all points lying between the two parallel lines (including points on the lines). Find the maximum possible total value.

Input Format

The first line contains an integer NN.
In the next NN lines, the ii-th line contains three integers Xi,Yi,WiX_i, Y_i, W_i separated by spaces.

Output Format

Output one line containing one integer, representing the maximum total value.

5
-5 5 -2
2 5 10
1 4 -2
4 -5 4
-2 2 7
19
6
0 0 6
1 0 -2
2 0 8
0 1 -2
1 1 5
2 1 -2
15
5
0 0 2
4 0 2
3 2 -1
1 2 2
1 1 -1
5
2
0 0 -1
1 0 -1
0

Hint

Sample Explanation 1.

Choose points 2,3,4,52, 3, 4, 5.

Sample Explanation 2.

Note that points 1,2,31, 2, 3 are collinear. Points 4,5,64, 5, 6 are collinear.

Sample Explanation 3.

In this sample, no three points are collinear. One chosen parallel line passes through points 1,21, 2, and the other passes through points 3,43, 4.

Constraints

All input testdata satisfy the following conditions.

1N20001\le N\le 2000, Xi,Yi109|X_i|, |Y_i|\le 10^9, 1Wi109(1iN)1\le |W_i|\le 10^9\:(1\le i\le N). (Xi,Yi)(Xj,Yj)(1i<jN)(X_i, Y_i)\ne (X_j, Y_j)\:(1\le i<j\le N).

Subtask Score N100N\le 100 No three points are collinear Let LL be a line in the plane passing through two distinct points, and let LL' be another line in the plane passing through two distinct points. Then LL and LL' are not parallel to each other Other conditions
11 55 × All points are on the xx-axis
22 2020 None
33 3535 ×
44 2020 ×
55 ×

Translated by ChatGPT 5