結果

問題 No.3588 Already Ready
コンテスト
ユーザー 蜜蜂
提出日時 2026-07-11 00:43:18
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 42 ms / 3,000 ms
+ 609µs
コード長 3,245 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,222 ms
コンパイル使用メモリ 365,320 KB
実行使用メモリ 14,356 KB
最終ジャッジ日時 2026-07-11 00:43:31
合計ジャッジ時間 7,581 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 69
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// g++-15 1.cpp -std=c++23 -O2 -I .

// 壊れるとき
// conda deactivate    # 何回か必要なことあり
// hash -r             # コマンドキャッシュクリア
// which -a ld
// ld の先頭が /usr/bin/ld になればそのままコンパイルしてOK


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

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;

#include <atcoder/convolution>
#include <atcoder/math>
#include <atcoder/modint>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

template <typename S, typename T>
istream& operator>>(istream& is, pair<S, T> &v){
  is >> v.first >> v.second;
  return is;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, pair<S, T> &v){
  os << v.first << " " << v.second << "\n";
  return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T> &v){
  for(T &e: v) is >> e;
  return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T> v){
  if(v.empty()){
    os<<"\n";
    return os;
  }
  for(int i=0;i<v.size()-1;i++)os<<v[i]<<" ";
  os<<v.back()<<"\n";
  return os;
}

random_device seed;
mt19937_64 randint(seed());

ll grr(ll mi, ll ma) { // [mi, ma)
    return mi + randint() % (ma - mi);
}

void solve(){
  int n,k,m;cin>>n>>k>>m;
  vll a(n);cin>>a;
  m--;
  rep(i,0,n){
    if(i==m)a[i]--;
    a[i]--;
  }
  if(a[m]<k){
    cout<<-1<<endl;
    return;
  }

  // 末尾に m をつける それ以外で終了しないようにしたい
  ll tot=accumulate(all(a),0LL);
  if(tot%(n+1)!=0){
    cout<<-1<<endl;
    return;
  }
  tot/=n+1;
  vi wins(n),lim(n);
  vvi event(k+1);
  rep(i,0,n){
    wins[i]=a[i]-tot;
    lim[i]=k-wins[i];
    if(wins[i]<0||lim[i]<0){
      cout<<-1<<endl;
      return;
    }
    event[lim[i]].emplace_back(i);
  }
  // cout<<wins<<lim;
  // i を wins[i] 個置く ただし最後の i は 0-ind で lim[i] 番目までに置く

  vi ans;
  pq_big(int) que;
  rep(i,tot,k+1){
    for(int ind:event[i]){
      rep(t,0,wins[ind])que.push(ind);
    }
  }
  per(i,tot-1,0){
    for(int ind:event[i]){
      rep(t,0,wins[ind])que.push(ind);
    }
    if(que.empty()){
      cout<<-1<<endl;
      return;
    }
    int tp=que.top();
    que.pop();
    ans.emplace_back(tp);
  }
  reverse(all(ans));
  cout<<ans.size()+1<<endl;
  for(int v:ans)cout<<v+1<<" ";
  cout<<m+1<<endl;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int t=1;
  // cin>>t;
  while(t--){
    solve();
  }
}
0