結果
| 問題 | No.3588 Already Ready |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-28 13:19:38 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,229 bytes |
| 記録 | |
| コンパイル時間 | 1,212 ms |
| コンパイル使用メモリ | 215,832 KB |
| 実行使用メモリ | 8,192 KB |
| 最終ジャッジ日時 | 2026-07-10 20:54:15 |
| 合計ジャッジ時間 | 6,379 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 TLE * 1 -- * 61 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main() {
int N, K, M;
cin >> N >> K;
cin >> M;
vector<int> A(N + 1);
long long 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;
}
long long 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) {
cout << -1 << '\n';
return 0;
}
if (A[M] - 2 < K) {
cout << -1 << '\n';
return 0;
}
int m = (int)(T - 1);
vector<int> B(N + 1, 0);
vector<int> rem(N + 1, 0);
vector<int> deadline(N + 1, INF);
vector<int> deadline_count(max(1, m) + 1, 0);
int sumB = 0;
for (int i = 1; i <= N; i++) {
int b = W[i] - (i == M ? 1 : 0);
if (b < 0) {
cout << -1 << '\n';
return 0;
}
B[i] = b;
rem[i] = b;
sumB += b;
if (b > 0) {
int d = K + 1 - b;
if (d < 1) {
cout << -1 << '\n';
return 0;
}
int effective_deadline = min(d, m);
deadline[i] = effective_deadline;
deadline_count[effective_deadline] += b;
}
}
assert(sumB == m);
if (m == 0) {
cout << 1 << '\n';
cout << M << '\n';
return 0;
}
vector<int> slack(m + 1, INF);
int pref = 0;
for (int x = 1; x <= m; x++) {
pref += deadline_count[x];
slack[x] = x - pref;
if (slack[x] < 0) {
cout << -1 << '\n';
return 0;
}
}
assert(pref == m);
vector<int> ans;
ans.reserve((size_t)T);
for (int p = 1; p <= m; p++) {
int min_deadline = INF;
for (int i = 1; i <= N; i++) {
if (rem[i] > 0) {
min_deadline = min(min_deadline, deadline[i]);
}
}
if (min_deadline < p) {
cout << -1 << '\n';
return 0;
}
int E = m + 1;
for (int x = p; x <= m; x++) {
if (slack[x] == 0) {
E = x;
break;
}
}
int c = -1;
for (int i = 1; i <= N; i++) {
if (rem[i] > 0 && deadline[i] <= E) {
c = i;
break;
}
}
if (c == -1) {
cout << -1 << '\n';
return 0;
}
ans.push_back(c);
for (int x = p; x < deadline[c]; x++) {
slack[x]--;
if (slack[x] < 0) {
cout << -1 << '\n';
return 0;
}
}
rem[c]--;
}
for (int i = 1; i <= N; i++) {
assert(rem[i] == 0);
}
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;
}