問題一覧 > 通常問題

No.165 Enclose Them in a Rectangle!

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 104
作問者 : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 264 / 自分の提出
問題文最終更新日: 2026-06-25 05:37:15
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 91 (順位表) の他の問題:

Problem Statement

On the $X\,Y$ coordinate plane, $N$ distinct points with integer coordinates are given.
Each point has a score assigned to it.
$A$-kun wants to enclose as many points as possible with a rectangle whose sides are parallel to the $X$-axis and $Y$-axis, in such a way that the rectangle does not overlap any point.
However, as a condition, the total score of the enclosed points must be at most $B$.
What is the maximum number of points that can be enclosed?

Input

$N$ $B$
$X_0$ $Y_0$ $P_0$
$X_1$ $Y_1$ $P_1$
 ...
$X_{N-1}$ $Y_{N-1}$ $P_{N-1}$

The number of points $N$ is given. ($1 \le N \le 400$)
The score $B$ that must not be exceeded is given. ($1 \le B \le 4000000$)
The information of the $N$ points with integer coordinates is given over $N$ lines.
$X_i$,$Y_i$ is the information of the $i$-th coordinates ($X_i$,$Y_i$). ($-1000000000 \le X_i,Y_i \le 1000000000$)
$P_i$ is the score of the $i$-th coordinates. ($1 \le P_i \le 10000$)
If $i \neq j $, then $(X_i,Y_i) \neq (X_j,Y_j)$.

Output

Output the maximum number of points that can be enclosed.
Do not forget the newline at the end.

Sample

Sample 1
Input
3 3
-1 0 1
0 0 2
1 0 3
Output
2

There are 3 points (-1,0), (0,0), and (1,0).
Their scores are 1, 2, and 3, respectively.
The total score of (-1,0) and (0,0) is at most 3, so these 2 points can be enclosed with a rectangle.

Sample 2
Input
3 3
-1 0 1
0 0 3
0 1 2
Output
1

There are 3 points (-1,0), (0,0), and (0,1).
Their scores are 1, 3, and 2, respectively.
Any 1 point among (-1,0), (0,0), and (0,1) can be enclosed with a rectangle.
Note that, since the enclosing is done with a rectangle, it is not possible to enclose only (-1,0) and (0,1) without enclosing (0,0).

Sample 3
Input
5 3
-1 0 100
0 1 100
0 0 2
0 -1 100
1 0 100
Output
1

There are 5 points.
Only the 1 point in the center can be enclosed with a rectangle.

Sample 4
Input
12 345
-3 74 32
68 -19 9
46 2 48
-20 -42 24
18 3 85
-31 -76 8
-80 32 82
-47 74 34
68 2 37
36 74 69
-50 -55 65
-55 18 26
Output
8

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。