提出 #58222301


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;

int main(){
    long long n, m, k, rem;
    cin >> n >> m >> k;
    rem = k;
    vector<long long> a(n), cum(n), ans(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        rem -= a[i];
    }

    vector<int> ind(n);
    iota(ind.begin(), ind.end(), 0);
    sort(ind.begin(), ind.end(), [&](int x, int y){return a[x] > a[y];});
    sort(a.begin(), a.end(), greater<long long>());

    auto sor = a;
    reverse(sor.begin(), sor.end());

    cum[0] = a[0];
    for(int i = 1; i < n; i++) cum[i] = cum[i-1] + a[i];

    for(int i = 0; i < n; i++){
        int in = ind[i];
        // cout << in << " " << a[i] << endl;
        long long lo = a[i], hi = rem + a[i], an = a[i]-1;
        while(hi >= lo){
            long long mid = (hi + lo) / 2;
            int pos = upper_bound(sor.begin(), sor.end(), mid) - sor.begin();
            pos = n - pos;
            if(pos >= m){
                lo = mid + 1;
                continue;
            }
            if(i < m){
                long long sum = cum[m] - (pos == 0? 0: cum[pos-1]);
                sum -= a[i];
                long long need = (mid + 1) * (m - pos) - sum;
                if(mid + need - a[i] <= rem){
                    lo = mid + 1;
                }
                else{
                    an = mid;
                    hi = mid - 1;
                }
            }
            else{
                long long sum = cum[m-1] - (pos == 0? 0: cum[pos-1]);
                long long need = (mid + 1) * (m - pos) - sum;
                if(mid + need - a[i] <= rem){
                    lo = mid + 1;
                }
                else{
                    an = mid;
                    hi = mid - 1;
                }
            }
        }
        ans[in] = an - a[i];
    }
    for(int i = 0; i < n; i++) cout << ans[i] << " \n"[i == n-1]; 
}

提出情報

提出日時
問題 E - How to Win the Election
ユーザ arnob918
言語 C++ 20 (gcc 12.2)
得点 500
コード長 1941 Byte
結果 AC
実行時間 314 ms
メモリ 10428 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 2
AC × 43
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 02_hand_00.txt, 02_hand_01.txt, 02_hand_02.txt, 02_hand_03.txt, 02_hand_04.txt, 02_hand_05.txt, 02_hand_06.txt, 02_hand_07.txt, 02_hand_08.txt, 02_hand_09.txt, 02_hand_10.txt, 02_hand_11.txt, 03_large_k_00.txt, 03_large_k_01.txt, 03_large_k_02.txt, 03_large_k_03.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3672 KiB
00_sample_01.txt AC 1 ms 3412 KiB
01_random_00.txt AC 93 ms 6264 KiB
01_random_01.txt AC 149 ms 7252 KiB
01_random_02.txt AC 215 ms 9900 KiB
01_random_03.txt AC 183 ms 8604 KiB
01_random_04.txt AC 161 ms 7024 KiB
01_random_05.txt AC 232 ms 10184 KiB
01_random_06.txt AC 1 ms 3468 KiB
01_random_07.txt AC 1 ms 3472 KiB
01_random_08.txt AC 1 ms 3472 KiB
01_random_09.txt AC 1 ms 3616 KiB
01_random_10.txt AC 2 ms 3696 KiB
01_random_11.txt AC 1 ms 3624 KiB
01_random_12.txt AC 271 ms 10284 KiB
01_random_13.txt AC 229 ms 10356 KiB
01_random_14.txt AC 234 ms 10300 KiB
01_random_15.txt AC 225 ms 10208 KiB
01_random_16.txt AC 224 ms 10276 KiB
01_random_17.txt AC 232 ms 10204 KiB
01_random_18.txt AC 304 ms 10260 KiB
01_random_19.txt AC 235 ms 10420 KiB
01_random_20.txt AC 127 ms 10264 KiB
01_random_21.txt AC 129 ms 10284 KiB
01_random_22.txt AC 121 ms 10268 KiB
01_random_23.txt AC 124 ms 10192 KiB
01_random_24.txt AC 127 ms 10196 KiB
02_hand_00.txt AC 203 ms 10260 KiB
02_hand_01.txt AC 198 ms 10188 KiB
02_hand_02.txt AC 195 ms 10208 KiB
02_hand_03.txt AC 204 ms 10276 KiB
02_hand_04.txt AC 206 ms 10188 KiB
02_hand_05.txt AC 205 ms 10200 KiB
02_hand_06.txt AC 194 ms 10428 KiB
02_hand_07.txt AC 202 ms 10288 KiB
02_hand_08.txt AC 36 ms 10256 KiB
02_hand_09.txt AC 68 ms 10188 KiB
02_hand_10.txt AC 52 ms 10240 KiB
02_hand_11.txt AC 314 ms 10300 KiB
03_large_k_00.txt AC 28 ms 4144 KiB
03_large_k_01.txt AC 18 ms 4008 KiB
03_large_k_02.txt AC 152 ms 8340 KiB
03_large_k_03.txt AC 8 ms 3824 KiB