提出 #58285054


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);

    ll N, M, K;
    cin >> N >> M >> K;
    vector<pair<ll, int>> A(N);
    vector<ll> ans(N);
    rep(i, 0, N){
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(all(A));
    reverse(all(A));
    vector<ll> sumA(N + 1);
    rep(i, 0, N) sumA[i + 1] = sumA[i] + A[i].first;
    if (N == M){
        rep(i, 0, N){
            cout << 0 << (i + 1 == N ? "\n" : " ");
        }
        return 0;
    }
    ll rem = K - sumA.back();
    ll ind = M - 1;
    ll val = -1;
    auto f = [&](ll i, ll j) -> ll {
        ll res = A[j].first * (M + 1 - j);
        res -= sumA[M] - sumA[j] + A[i].first;
        return res - 1;
    };
    for (ll i = N - 1; i >= M; i--){
        while (ind != 0){
            if (f(i, ind - 1) >= rem) break;
            ind--;
        }
        val = A[ind].first;
        val += (rem - f(i, ind)) / (M + 1 - ind);
        ans[A[i].second] = val - A[i].first;
    }
    rep(i, 0, M) ans[A[i].second] = val - A[i].first;
    rep(i, 0, N){
        if (ans[i] < 0) ans[i] = 0;
        if (ans[i] > rem) ans[i] = -1;
        cout << ans[i] << (i + 1 == N ? "\n" : " ");
    }
}

提出情報

提出日時
問題 E - How to Win the Election
ユーザ potato167
言語 C++ 17 (gcc 12.2)
得点 500
コード長 1404 Byte
結果 AC
実行時間 39 ms
メモリ 9544 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 3432 KiB
00_sample_01.txt AC 1 ms 3384 KiB
01_random_00.txt AC 17 ms 5612 KiB
01_random_01.txt AC 21 ms 6568 KiB
01_random_02.txt AC 37 ms 9084 KiB
01_random_03.txt AC 29 ms 8056 KiB
01_random_04.txt AC 22 ms 6708 KiB
01_random_05.txt AC 37 ms 9424 KiB
01_random_06.txt AC 1 ms 3516 KiB
01_random_07.txt AC 1 ms 3580 KiB
01_random_08.txt AC 1 ms 3564 KiB
01_random_09.txt AC 1 ms 3456 KiB
01_random_10.txt AC 1 ms 3528 KiB
01_random_11.txt AC 1 ms 3608 KiB
01_random_12.txt AC 38 ms 9360 KiB
01_random_13.txt AC 37 ms 9528 KiB
01_random_14.txt AC 37 ms 9336 KiB
01_random_15.txt AC 37 ms 9380 KiB
01_random_16.txt AC 37 ms 9380 KiB
01_random_17.txt AC 37 ms 9364 KiB
01_random_18.txt AC 37 ms 9452 KiB
01_random_19.txt AC 37 ms 9416 KiB
01_random_20.txt AC 36 ms 9396 KiB
01_random_21.txt AC 37 ms 9412 KiB
01_random_22.txt AC 35 ms 9416 KiB
01_random_23.txt AC 38 ms 9468 KiB
01_random_24.txt AC 38 ms 9544 KiB
02_hand_00.txt AC 27 ms 9472 KiB
02_hand_01.txt AC 28 ms 9308 KiB
02_hand_02.txt AC 25 ms 9348 KiB
02_hand_03.txt AC 26 ms 9392 KiB
02_hand_04.txt AC 27 ms 9476 KiB
02_hand_05.txt AC 26 ms 9344 KiB
02_hand_06.txt AC 39 ms 9368 KiB
02_hand_07.txt AC 38 ms 9372 KiB
02_hand_08.txt AC 20 ms 9260 KiB
02_hand_09.txt AC 37 ms 9364 KiB
02_hand_10.txt AC 39 ms 9472 KiB
02_hand_11.txt AC 34 ms 9364 KiB
03_large_k_00.txt AC 6 ms 4060 KiB
03_large_k_01.txt AC 5 ms 3912 KiB
03_large_k_02.txt AC 27 ms 7792 KiB
03_large_k_03.txt AC 2 ms 3768 KiB