感受



思路







#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 300 + 10;
const ll mod = 998244353;
int n, m;
int cost[maxn][maxn];
int cnt[maxn];
ll ans;
int main(){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            scanf("%d", &cost[i][j]);
        }
        sort(cost[i] + 1, cost[i] + m + 1);
    }
    for(int i = 1; i <= n; i++){
        ll res = 1e18, tmp; int id;
        for(int j = 1; j <= i; j++){
            if(cnt[j] == m) continue;
            tmp = (ll)2 * cnt[j] + 1 + cost[j][cnt[j] + 1];
            if(res > tmp){
                res = tmp; id = j;
            }
        }
        cnt[id]++; ans += res;
    }
    printf("%lld\n", ans);
    return 0;
}