Submission #345473

#TimeUsernameProblemLanguageResultExecution timeMemory
345473l3nl3UFO (IZhO14_ufo)C++14
35 / 100
2090 ms8940 KiB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>  
 
#define exit exit(false)
 
//#define here() cerr << "herewego\n";
#define show(x) cerr << #x << ": " << x << '\n';
 
#define int long long
//#define double long double
 
#define all(a) a.begin(), a.end()
#define whole(a, p, q) a+p, a+p+q
 
#define ioio() ios_base::sync_with_stdio (0); cin.tie (0); cout.tie (0);
 
using namespace std;
 
//using namespace __gnu_pbds;   
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;  
 
signed main () { ioio();
	int n, m, r, k, p;
	cin >> n >> m >> r >> k >> p;
	int a[n+1][m+1];
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}
	while (k--) {
		char tp;
		int x, h;
		cin >> tp >> x >> h;
		int cn = r;
		if (tp == 'N') {
			int y = 1;
			while (y <= n && cn > 0) {
				if (a[y][x] >= h) {
					cn--;
					a[y][x]--;
				}
				y++;
			}
		} else if (tp == 'S') {
			int y = n;
			while (y >= 1 && cn > 0) {
				if (a[y][x] >= h) {
					cn--;
					a[y][x]--;
				}
				y--;
			}
		} else if (tp == 'W') {
			int y = 1;
			while (y <= m && cn > 0) {
				if (a[x][y] >= h) {
					cn--;
					a[x][y]--;
				}
				y++;
			}
		} else {
			int y = m;
			while (y >= 1 && cn > 0) {
				if (a[x][y] >= h) {
					cn--;
					a[x][y]--;
				}
				y--;
			}
		}
	}
	/*for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cout << a[i][j] << ' ';
		} 
		cout << '\n';
	}*/
	int mx = -1;
	for (int i = p; i <= n; i++) {
		for (int j = p; j <= m; j++) {
			int sm = 0;
			for (int x = i - p + 1; x <= i; x++) {
				for (int y = j - p + 1; y <= j; y++) {
					sm += a[x][y];
				}
			}
			mx = max (mx, sm);
		}
	}
	cout << mx;
}
#Verdict Execution timeMemoryGrader output
Fetching results...