悲!60pits
查看原帖
悲!60pits
920843
bylgd楼主2023/9/29 18:27
#include <bits/stdc++.h>
int a[25][25];
using namespace std;
typedef pair<int, int> PII;
int m, n, k;
PII get_max() {
	PII r = {0, 0};
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= m; j ++ )
			if (a[i][j] > a[r.first][r.second])
				r = {i, j};
	return r;
}
int main() {
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= m; j ++ )
			cin >> a[i][j];
	PII t = get_max();
	if (t.first * 2 + 1 > k) puts("0");
	else {
		int res = a[t.first][t.second];
		a[t.first][t.second] = 0;
		k -= t.first + 1;
		while (true) {
			PII r = get_max();
			int time = abs(t.first - r.first) + abs(t.second - r.second) + 1;
			if (time + r.first > k) break;
			res += a[r.first][r.second];
			a[r.first][r.second] = 0;
			k -= time;
		}
		cout << res << endl;
	}
	return 0;
}
2023/9/29 18:27
加载中...