Files
python/TangDou/Topic/PrefixAndSuffix/P2004.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

27 lines
778 B
C++

#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m, c;
int a[N][N], s[N][N];
int mx = INT_MIN;
int main() {
cin >> n >> m >> c;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j]; // 构建二维前缀和
}
int x, y;
for (int i = c; i <= n; i++) // 边长为c
for (int j = c; j <= m; j++) {
if (s[i][j] - s[i - c][j] - s[i][j - c] + s[i - c][j - c] > mx) {
mx = s[i][j] + s[i - c][j - c] - s[i - c][j] - s[i][j - c];
x = i - c + 1;
y = j - c + 1;
}
}
printf("%d %d", x, y);
return 0;
}