結果

問題 No.3588 Already Ready
コンテスト
ユーザー marc2825
提出日時 2026-05-28 13:22:25
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,687 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,107 ms
コンパイル使用メモリ 213,416 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2026-07-10 20:54:34
合計ジャッジ時間 8,595 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 WA * 5 TLE * 1 -- * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

using ll = long long;

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

    int N, K, M;
    cin >> N >> K;
    cin >> M;

    vector<int> A(N + 1);
    ll S = 0;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        S += A[i];
    }

    if (S % (N + 1) != 0) {
        cout << -1 << '\n';
        return 0;
    }

    ll T = S / (N + 1);
    if (T < 1) {
        cout << -1 << '\n';
        return 0;
    }

    vector<int> W(N + 1);
    for (int i = 1; i <= N; i++) {
        W[i] = A[i] - T;
        if (W[i] < 0) {
            cout << -1 << '\n';
            return 0;
        }
    }

    if (W[M] < 1 || A[M] - 2 < K) {
        cout << -1 << '\n';
        return 0;
    }

    int m = (int)T - 1;
    vector<int> rem(N + 1);

    for (int i = 1; i <= N; i++) {
        rem[i] = W[i] - (i == M ? 1 : 0);
        if (rem[i] < 0) {
            cout << -1 << '\n';
            return 0;
        }
    }

    vector<int> ans;

    for (int p = 1; p <= m; p++) {
        int c = -1;
        for (int i = 1; i <= N; i++) {
            if (rem[i] > 0) {
                c = i;
                break;
            }
        }

        if (c == -1) {
            cout << -1 << '\n';
            return 0;
        }

        int before_score = (p - 1) + (W[c] - rem[c]);
        if (before_score >= K) {
            cout << -1 << '\n';
            return 0;
        }

        ans.push_back(c);
        rem[c]--;
    }

    ans.push_back(M);

    cout << ans.size() << '\n';
    for (int i = 0; i < (int)ans.size(); i++) {
        if (i) cout << ' ';
        cout << ans[i];
    }
    cout << '\n';

    return 0;
}
0