Huang question upset how to do online wait very urgent ah ...
I read the subject in earnest.
I cried, what about you?
One punch, one tear-eye freak.
This question looks like a prefix and one at a glance. Then I was in the mood to write a dash, handed up 10pt,wa sound a piece.
The original idea was mentally retarded, and I thought the stars he gave were given in ascending order of X.
And one more thing: the stars may overlap. A point may have more than one star. That's all I'm not thinking about.
So what's the best way?
Open a B-array directly, recording the brightness of the stars for each x-coordinate.
If asked, first preprocess the prefix and then the \ (n\) ( O (1) \) query. Complexity \ (O (n) \).
Code:
#include<cstdio>#include<algorithm>const int maxn = 100005;int maxx;int b[maxn];int n, w;int main(){ scanf("%d%d", &n, &w); for(int i = 1; i <= n; i++) { int xx, bb; scanf("%d%d", &xx, &bb); b[xx] += bb; maxx = std::max(maxx, xx); } for(int i = 1; i <= maxx; i++) b[i] += b[i - 1]; int ans = -19260817; for(int i = 1; i + w - 1 <= maxx; i++) { ans = std::max(ans, b[i + w - 1] - b[i - 1]); } printf("%d\n", ans); return 0;}
P3353 the stars shining outside your window