1 条题解

  • 0
    @ 2023-5-18 20:13:06
    不用做得太认真 好吧!
    
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int MXN = 100 + 5;
    const int p = 13131;//233333, 19260817
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    typedef unsigned long long ull;
    int n, m, k;
    struct node {
        int x, y;
        int val;
    };
    node cw[4005];
    bool cmp(const node &a, const node &b) {
        
        
        return a.val > b.val;
    }
    int main() {
        scanf("%d%d%d", &n, &m, &k);
        int cnt = 0;
        for(int i = 1; i <= n; ++i) {
            for(int j = 1, v; j <= m; ++j) {
                scanf("%d", &v);
                if(v > 0) {
                    cw[cnt].x = i, cw[cnt].y = j;
                    cw[cnt ++].val = v;
                }
            }
        }
        sort(cw, cw + cnt, cmp); O(nlog(n))
        int ans = 0;
        for(int i = 0; i < cnt; ++i) {
            if(i == 0) {
                if(cw[i].x + cw[i].x + 1 <= k) {
                    ans += cw[i].val;
                    k -= cw[i].x + 1;
                }else break;
            }else {
                if(abs(cw[i-1].x-cw[i].x) + abs(cw[i-1].y-cw[i].y) + cw[i].x + 1 <= k) {
                    ans += cw[i].val;
                    k -= abs(cw[i-1].x-cw[i].x) + abs(cw[i-1].y-cw[i].y) + 1;
                }else break;
            }
        }
        printf("%d\n", ans);
        return 0;
    }
    
    • 1

    信息

    ID
    1860
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    7
    已通过
    2
    上传者