比赛 20241129 评测结果 AAAAAAAAAA
题目名称 棋局 最终得分 100
用户昵称 darkMoon 运行时间 0.445 s
代码语言 C++ 内存使用 4.06 MiB
提交时间 2024-11-29 09:59:47
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
auto IN = freopen("qiju.in", "r", stdin);
auto OUT = freopen("qiju.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 2e5 + 5;
int n = mread(), m = mread(), a[N], sum[N];
bool check(int x, int mid){
    // 要求最多 mid 个列大于等于 x
    int p = lower_bound(a + 1, a + 1 + n, mid) - a;
    return sum[p] - (n - p + 1) * mid <= (x - 1) * (m - mid);
}
signed main(){
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    for(int i = n; i >= 1; i --){
        sum[i] = sum[i + 1] + a[i];
    }
    for(int i = 1; i <= n; i ++){
        int l = 0, r = m;
        while(l < r){
            int mid = l + r >> 1;
            if(check(i, mid)){
                r = mid;
            }
            else{
                l = mid + 1;
            }
        }
        printf("%lld ", l);
    }
    return 0;
}