6 7 21 0 0 0 0 0 0 0 0 0 0 0 13 0 0 0 0 0 0 0 0 7 0 15 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0
37
#include<bits/stdc++.h> using namespace std; #define ll long long #define eps 1e-9 #define pi acos(-1) const int inf = 0x3f3f3f3f; const int mod = 1000000007; const int maxn = 1000 + 8; int n, m, k; struct node { int x, y, w; }t[maxn]; bool cmp(node a, node b) { return a.w > b.w; } int main() { std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; int id = 0; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) { t[++id] = {i, j, 0}; cin >> t[id].w; } sort(t + 1, t + n * m + 1, cmp); t[0].x = 0; t[0].y = t[1].y; int ans = 0; for(int i = 1; i <= n * m; i++) { k -= abs(t[i - 1].x - t[i].x) + abs(t[i - 1].y - t[i].y) + 1; if(k < t[i].x)break; ans += t[i].w; } cout << ans << ‘\n‘; return 0; }
原文:https://www.cnblogs.com/RootVount/p/11480214.html