P3353 The Stars Shining Outside Your Window
Background
The fleeting passage of time will not blur my memory of you. It is hard to believe that 3 years have passed since I first saw you. I still vividly remember, 3 years ago, at the beautiful Jimei Middle School, when I saw you walk out of the classroom with a smile, tilt your head back, and the soft evening glow lit up your rosy cheeks. I knew I was already enchanted by you. Later, after months of watching and peeking, your grace and wisdom, your attitude toward life, and your hopes for the future left a deep impression on me. You are a charming sunshine girl, and I always dream of spending the rest of my life with you. Alas, in fact you far exceed my wildest dreams. I do not know how to bridge the gap between you and me. So I had no plan, only waiting, waiting for a proper chance to come. Until now, with graduation approaching, I realize I am a fool; I should create chances and seize them, not just wait.
These days, my friends, roommates, and classmates are parting one by one. I still cannot believe that after we wave goodbye, those familiar faces will soon disappear from our lives, leaving only memories. I will leave school tomorrow. You have planned to go far away, pursue your future, and realize your dreams. Without fate, perhaps we will never meet again. So tonight, I am wandering downstairs by your dormitory, hoping to run into you by chance. But paradoxically, your beauty will certainly make my heart pound, and my clumsy tongue may not utter a word. I do not remember how many times I have passed by your dormitory, each time hoping to see you appear on the balcony or by the window. I do not remember how many times the thought has surged in my mind: call you to have dinner together or just chat. But each time, thinking of your excellence and my ordinariness, timidity outweighs courage and drives me to leave quietly.
Graduation means the end of middle school life. Those glorious and romantic days are over. Your lovely smile was the motivation behind my hard study, and this unrequited love will be sealed as a memory deep in my heart. Graduation also means the start of a new life, a step toward a bright future. I truly wish you happiness every day abroad and all the best. At the same time, I will try to grow out of childishness and become more mature. My ideal is to pursue love and happiness in reality, and I will never give up.
Farewell, my princess.
If one day, somewhere at the ends of the earth, we have the chance to meet again, even as a gray‑haired man and woman, then I hope we can be good friends, proudly share this memory, and relive the passion of our youthful joy. If that chance never comes, I wish I were a star in the sky, twinkling outside your window. Blessing you from afar, like a friend, by your side every night, sharing sweet dreams with you or going through terrible dreams together.
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 $X_i$ and a brightness $B_i$. **Multiple stars may share the same position.** The range a window can see is given by a parameter $W$, 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, W$, the number of stars and the width of the window.
Each of the next $N$ lines contains $X_i$ and $B_i$, the coordinate and brightness of a star.
Output Format
One number, the maximum total brightness of the visible stars.
Explanation/Hint
Sample explanation:

Constraints:
- For $10\%$ of the testdata, $W = 0$ (no boundary).
- For $40\%$ of the testdata, $W \leq 1000$.
- For $100\%$ of the testdata, $1 \leq N \leq 10^5$, $0 \leq W \leq 10^5$, $1 \leq X_i \leq 10^5$, $1 \leq B_i \leq 100$.
- Except for the case $W = 0$, $W$ is an odd integer $\geq 3$.
Translated by ChatGPT 5