#P3353. Maximum Visible Stars Brightness
Maximum Visible Stars Brightness
Maximum Visible Stars Brightness
Consider the sky as a number line along which many stars are located. Each star has a position \(X_i\) and a brightness value \(B_i\). Note that multiple stars can share the same position.
A window that has a viewing range of width \(W\) can be moved along the number line, and a star is considered visible if its position lies within or exactly on the boundaries of the window.
Your task is to determine the maximum sum of brightness of the stars that can be observed by optimally positioning the window.
inputFormat
The first line contains two integers \(N\) and \(W\) where \(N\) is the number of stars and \(W\) is the width of the window.
Each of the following \(N\) lines contains two integers \(X_i\) and \(B_i\), representing the position and brightness of a star.
outputFormat
Output a single integer denoting the maximum sum of brightness that can be observed by the window.
sample
5 10
1 2
3 5
15 10
10 3
8 7
20