#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m, R, K, P;
cin >> n >> m >> R >> K >> P;
vector<vector<int>> a(n, vector<int>(m));
for (auto &i : a) {
for (auto &j : i)
cin >> j;
}
while (K--) {
char c;
int x, h;
cin >> c >> x >> h; x--;
if (c == 'N' || c == 'S') {
int cnt = R;
for (int i = (c == 'N' ? 0 : n - 1); 0 <= i && i < n && cnt; i += (c == 'N' ? 1 : -1)) {
if (h <= a[i][x]) {
cnt--;
a[i][x]--;
}
}
}
else {
int cnt = R;
for (int i = (c == 'W' ? 0 : m - 1); 0 <= i && i < m && cnt; i += (c == 'W' ? 1 : -1)) {
if (h <= a[x][i]) {
cnt--;
a[x][i]--;
}
}
}
}
ll mx = 0;
for (int i = 0; i + P <= n; i++) {
for (int j = 0; j + P <= m; j++) {
ll sm = 0;
for (int x = i; x < i + P; x++) {
for (int y = i; y < i + P; y++)
sm += a[x][y];
}
mx = max(mx, sm);
}
}
cout << mx;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |