首先被题目甜到了
本来搜标签搜的线段树,结果发现这题目很吸引我我果断点开
觉得前缀和就能A啊
于是乎
要注意
窗户旁边是可以看到的
所以前缀和的时候是不用再-1的
//前缀和 //注意坑点 //窗户的边缘可以看到 #include <cstdio> #include <iostream> using namespace std; const int N = 100010; int n, m, a[N], you = 1, ans = -0x3f3f3f3f, qzh[N]; int read() { int s = 0, w = 1; char ch = getchar(); while(!isdigit(ch)) {if(ch == '-') w = -1;ch = getchar();} while(isdigit(ch)) {s = s * 10 + ch - '0';ch = getchar();} return s * w; } int main() { n = read(), m = read(); for(int i = 1; i <= n; i++) { int x, y; x = read(), y = read(); a[x] += y; you = max(you, x); } for(int i = 1; i <= you; i++) qzh[i] = qzh[i - 1] + a[i]; for(int i = 1; i <= you; i++) ans = max(ans, qzh[i] - qzh[i - m]); printf("%d ", ans); return 0; }
谢谢收看, 祝身体健康!