#P3357. 最长k可重线段集问题

最长k可重线段集问题

Description

Given a set II of nn open line segments in the plane xOyx-O-y, and a positive integer kk. Design an algorithm to select a subset SIS \subseteq I such that, for any point pp on the xx-axis, the number of open line segments in SS that intersect the line x=px = p does not exceed kk, and zSz\sum\limits_{z\in S} |z| is maximized. Such a subset SS is called the longest kk-overlap set of open line segments of II. The value zSz\sum\limits_{z\in S} |z| is called the length of the longest kk-overlap segment set.

For any open line segment zz with endpoints (x0,y0)(x_0, y_0) and (x1,y1)(x_1, y_1), its length z|z| is defined as:

z=(x1x0)2+(y1y0)2|z|=\lfloor\sqrt{(x_1-x_0)^2+(y_1-y_0)^2}\rfloor

Given the open line segment set II and the positive integer kk, compute the length of the longest kk-overlap open segment set of II.

Input Format

The first line contains 22 positive integers nn and kk, denoting the number of open line segments and the allowed overlap count.

The next nn lines each contain 44 integers, giving the coordinates of the 22 endpoints of an open line segment.

Output Format

Output the computed length of the longest kk-overlap segment set.

4 2
1 2 7 3
6 5 8 3
7 8 10 5
9 6 13 9 
17

Hint

Constraints: 1n5001 \leq n \leq 500, 1k131 \leq k \leq 13, and all coordinates are within the int range.

Translated by ChatGPT 5