No.3214 small square
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もしくは右上の雲マークをクリックしてアカウントを作成してください。
Cafe1942