NC14526(购物 )

感受



思路







#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;
}
全部评论

相关推荐

但听说转正率很低,我现在有在实习了,好纠结要不要去
熬夜脱发码农:转正率低归低,但是实习的经历你可以拿着,又不是说秋招不准备了
点赞 评论 收藏
分享
下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
找工作时遇到的神仙HR
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务