結果

問題 No.3588 Already Ready
コンテスト
ユーザー baluteshih
提出日時 2026-07-11 14:51:20
言語 C++23(gnu拡張gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 31 ms / 3,000 ms
+ 263µs
コード長 4,004 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,431 ms
コンパイル使用メモリ 367,820 KB
実行使用メモリ 8,124 KB
最終ジャッジ日時 2026-07-11 14:52:02
合計ジャッジ時間 6,001 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 69
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#line 2 "/Users/baluteshih/coding/cplibrary/default_code.hpp"

#line 2 "/Users/baluteshih/coding/cplibrary/assumption.hpp"

#include <cassert>
#include <bits/stdc++.h>
#line 4 "/Users/baluteshih/coding/cplibrary/default_code.hpp"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
template <typename T>
concept PrintableContainer = requires(T& a) {
    a.begin();
    a.end();
} && !std::convertible_to<std::remove_cvref_t<T>, std::string_view>; 
template<class A, class B>
ostream& operator<<(ostream& os, const pair<A, B> &a);
template <PrintableContainer T>
std::ostream& operator<<(std::ostream& os, const T& a);
template<class A, class B>
ostream& operator<<(ostream& os, const pair<A, B> &a) {
    os << "(" << a.first << ", " << a.second << ")";
    return os;
}
template <PrintableContainer T>
std::ostream& operator<<(std::ostream& os, const T& a) {
    os << "[ ";
    bool first = true;
    for (const auto& item : a) {
        if (!first) os << ", ";
        os << item;
        first = false;
    }
    return os << " ]";
}
#ifdef bbq
#include <experimental/iterator>
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define sepline sepline_() 
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
    cerr << "\e[1;32m(" << s << ") = (";
    int f = 0;
    (..., (cerr << (f++ ? ", " : "") << a));
    cerr << ")\e[0m\n";
}
void orange_(auto s, auto L, auto R) {
    cerr << "\e[1;33m[ " << s << " ] = [ ";
    using namespace experimental;
    copy(L, R, make_ostream_joiner(cerr, ", "));
    cerr << " ]\e[0m\n";
}
void sepline_(int length = 50) {
    cerr << "\e[1;35m";
    cerr << string(length, '=');
    cerr << "\e[0m\n";
}
#else
#define safe ((void)0)
#define sepline safe
#define debug(...) safe
#define orange(...) safe
#endif
void chmax(auto &x, auto val) { x = max(x, val); }
void chmin(auto &x, auto val) { x = min(x, val); }
auto floor_div(auto a, auto b) { return a / b - (a % b && (a < 0) ^ (b < 0)); }
auto ceil_div(auto a, auto b) { return a / b + (a % b && (a < 0) ^ (b > 0)); }
string bitstring(auto x, int width = -1) {
    string res;
    while (x) res.push_back((x & 1) + '0'), x >>= 1;
    if (res.empty()) res = "0";
    if (width != -1) res.resize(width, '0');
    ranges::reverse(res);
    return res;
}
vector<int> count_array(const auto &container, int sz = -1) {
    if (sz == -1) sz = *ranges::max_element(container) + 1;
    vector<int> res(sz);
    for (auto x : container) ++res[x];
    return res;
}
#line 2 "E.cpp"

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n, k, m;
    cin >> n >> k >> m, --m;
    vector<int> arr(n);
    for (int &i : arr)
        cin >> i;
    if (accumulate(ALL(arr), 0LL) % (n + 1) != 0)
        return cout << "-1\n", 0;
    if (arr[m] <= k + 1)
        return cout << "-1\n", 0;
    int mx = 0;
    for (int i = 0; i < n; ++i)
        if (i != m)
            chmax(mx, arr[i]);
    arr[m] -= 1;
    for (int i = 0; i < n; ++i) --arr[i];
    int race = accumulate(ALL(arr), 0LL) / (n + 1);
    vector<int> ans, win(n), ord(n);
    for (int i = 0; i < n; ++i) {
        if (arr[i] < race)
            return cout << "-1\n", 0;
        win[i] = arr[i] - race;
    }
    iota(ALL(ord), 0);
    ranges::sort(ord, [&](int a, int b) {
        return arr[a] < arr[b];
    });
    ans.resize(race);
    priority_queue<int> pq;
    for (int i = race - 1, j = 0; i >= 0; --i) {
        while (j < n && i + win[ord[j]] - 1 < k) {
            if (win[ord[j]] > 0) pq.push(ord[j]);
            ++j;
        }
        if (pq.empty())
            return cout << "-1\n", 0;
        ans[i] = pq.top(), pq.pop();
        if (--win[ans[i]] > 0) pq.push(ans[i]);
    }
    ans.push_back(m);
    cout << SZ(ans) << "\n";
    for (int i = 0; i < SZ(ans); ++i)
        cout << ans[i] + 1 << " \n"[i + 1 == SZ(ans)];
}
0