#P3353. 在你窗外闪耀的星星

在你窗外闪耀的星星

Description

Now here is the problem: Think of the sky as a number line. On this number line there are many stars, each with a position XiX_i and a brightness BiB_i. Multiple stars may share the same position. The range a window can see is given by a parameter WW, and the stars we see also include those on the window’s boundaries. Find the maximum possible sum of brightness of the stars visible after adjusting the position of the window.

Input Format

One line with N,WN, W, the number of stars and the width of the window.

Each of the next NN lines contains XiX_i and BiB_i, the coordinate and brightness of a star.

Output Format

One number, the maximum total brightness of the visible stars.

6 3
1 2
2 4
3 8
4 4
5 2
1000 1
16

Hint

Sample explanation:

Constraints:

  • For 10%10\% of the testdata, W=0W = 0 (no boundary).
  • For 40%40\% of the testdata, W1000W \leq 1000.
  • For 100%100\% of the testdata, 1N1051 \leq N \leq 10^5, 0W1050 \leq W \leq 10^5, 1Xi1051 \leq X_i \leq 10^5, 1Bi1001 \leq B_i \leq 100.
  • Except for the case W=0W = 0, WW is an odd integer 3\geq 3.

Translated by ChatGPT 5