https://www.acwing.com/problem/content/101/
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 10; int N, R, x, y, z, a[maxn][maxn], r, c, ans; int main() { cin >> N >> R; r = c = R; for (int i = 1; i <= N; i++) { cin >> x >> y >> z; x++; y++; a[x][y] = z; r = max(r, x); c = max(c, y); } for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1]; } } for (int i = R; i <= r; i++) { for (int j = R; j <= c; j++) { ans = max(ans, a[i][j] - a[i - R][j] - a[i][j - R] + a[i - R][j - R]); } } cout << ans << endl; return 0; }
为什么要++