Under construction

Still being built. Things may change

Darts Game

Time limit2sMemory limit512 MB

Summary
Given N scored darts, find the maximum total score inside a square of side L centered at the origin, where the square may be rotated to any angle.
Level

Medium7 of 10

Topics
Geometry, Sorting, Intervals
Solved
No attempts yet

Problem

Darts is a fun game. The game in this problem is a bit different.

The board can be considered as an infinite 2-dimensional plane, and you have already shot NN darts. Each dart is at a point (X,Y)(X, Y) and has a score SS. Several darts can be at the exact same location, even with different scores. A score can be negative.

After shooting all the darts, you must draw a square on the plane. The side length of the square must be LL, and the point (0,0)(0, 0) must be exactly at the center of the square. You can rotate the square in any direction you want. You can rotate it only once, before considering any darts.

You get the score of every dart that is inside the square or on its boundary. Given the location and score of each dart and the value of LL, find the maximum score you can get. The square is allowed to contain no darts.

Input

Your program will be tested on one or more test cases. The first line contains an integer TT (1≤T≤1001 \le T \le 100), the number of test cases.

Each test case starts with a line containing two integers NN (1≤N≤1051 \le N \le 10^5) and LL (1≤L≤1051 \le L \le 10^5), separated by a space. Then NN lines follow. Each line contains three integers XX, YY, SS, separated by spaces. This means there is a dart at (X,Y)(X, Y) that gives score SS. All values satisfy −105≤X,Y,S≤105-10^5 \le X, Y, S \le 10^5.

Output

For each test case, print one line with the maximum score you can get by drawing the square.

Hint

The figure shows the first test case. No placement of the square includes the point with score 100, but if you rotate the square slightly, it no longer includes the point with score -101.

Examples1

  1. Example 1

    Input
    2
    5 8
    4 5 100
    3 3 4
    -2 -2 -3
    -1 1 2
    4 -1 -101
    7 10
    1 1 -10
    -1 1 -10
    1 -1 -10
    -1 -1 -10
    0 1 -10
    1 0 -10
    2 2 -1000
    
    Expected output
    3
    -1060