#P1502. 窗口的星星

窗口的星星

Description

At night, Xiao Ka looks out from the balcony and exclaims, “Wow, so many stars!”, but he has not yet set a window for the other rooms.

Naive as he is, Xiao Ka always hopes to see the most and brightest stars at night, but the window’s size is fixed and its sides must be parallel to the ground. He uses a superpower (clairvoyance) to learn the position and brightness of every star behind the wall. However, using the superpower makes him tired, so he asks you to tell him the maximum possible total brightness of stars that can appear in the window.

Input Format

This problem has multiple test cases. The first line is TT, indicating there are TT test cases.

For each test case:

  • The first line has 33 integers n,W,Hn, W, H, meaning there are nn stars, and the window has width WW and height HH.
  • The next nn lines each contain three integers xi,yi,lix_i, y_i, l_i, meaning there is a star at coordinate (xi,yi)(x_i, y_i) with brightness lil_i.

Output Format

Output TT integers, each being the maximum total brightness of stars that can appear in the window for the corresponding test case.

2

3 5 4
1 2 3
2 3 2
6 3 1

3 5 4
1 2 3
2 3 2
5 3 1
5
6

Hint

For ease of understanding, blank lines are added between test cases in the sample input, but the actual testdata contains no blank lines.

The window frame is made of metal, so stars on the boundary do not count.

Constraints: For 100%100\% of the testdata: 1T101 \le T \le 10, 1n1041 \le n \le 10^4, 1W,H1061 \le W, H \le 10^6, 0li10000 \le l_i \le 1000, 0xi,yi<2310 \le x_i, y_i < 2^{31}.

Translated by ChatGPT 5