問題一覧 > 通常問題

No.3214 small square

レベル : / AI推定難易度 : 2000 / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 35
作問者 : Cafe1942 / テスター : 👑 loop0919 lif4635 yuusaan
お気に入りにしたユーザー ProblemId : 12480 / 自分の提出
問題文最終更新日: 2025-07-26 01:06:53
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 475 (ゆるCafe) (順位表) の他の問題:

Problem Statement

There are $N$ points on a two-dimensional plane. The coordinates of the $i\; (1 \leq i \leq N)$-th point are $(X_i,Y_i)$, and the value of the point is $V_i$.

Suppose you specify exactly $1$ square whose every side is parallel to one of the coordinate axes and whose side length is $A$. Output the maximum possible total value of the points inside the square (including its boundary).

Constraints

  • $1 \leq N \leq 10^{5}$
  • $-10^9 \leq X_i , Y_i \leq 10^9 $
  • $-10^9 \leq V_i \leq 10^9 $
  • $1 \leq A \leq 10^9 $
  • All inputs are integers.

Input

$N$ $A$
$X_1$ $Y_1$ $V_1$
$X_2$ $Y_2$ $V_2$
$\vdots$
$X_N$ $Y_N$ $V_N$

Output

Suppose you specify exactly $1$ square whose every side is parallel to one of the coordinate axes and whose side length is $A$. Output the maximum possible total value of the points inside the square (including its boundary).

Sample

Sample 1
Input
4 3
3 5 9
7 8 25
4 3 18
-1 2 -14
Output
27

By choosing the square region $ 2 \leq X \leq 5$ , $3 \leq Y \leq 6$, a total value of $27$ can be achieved.

Sample 2
Input
3 4
1 0 -2
5 0 3
6 0 -4
Output
3
Sample 3
Input
9 2
0 0 -3
1 0 2
2 0 3
2 0 2
3 0 -3
0 2 -4
1 2 1
2 2 1
3 2 -4
Output
9

There may be multiple points at exactly the same coordinates.

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