結果
| 問題 |
No.1872 Dictionary Order
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-03-11 22:51:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 1,540 bytes |
| コンパイル時間 | 1,573 ms |
| コンパイル使用メモリ | 175,192 KB |
| 実行使用メモリ | 18,944 KB |
| 最終ジャッジ日時 | 2024-09-19 08:43:10 |
| 合計ジャッジ時間 | 2,687 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;
#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll N, M;
cin >> N >> M;
V<ll> A(N), P(N);
rep(i, N) cin >> A[i];
rep(i, N) {
cin >> P[i];
P[i]--;
}
V<V<int>> dp(N + 1, V<int>(M + 1, 0));
dp[N][0] = 1;
for (int i = N - 1; i >= 0; i--) {
for (int j = 0; j <= M; j++) {
if (dp[i + 1][j] == 0) continue;
dp[i][j] = 1;
if (j + A[i] <= M) dp[i][j + A[i]] = 1;
}
}
if (dp[0][M] == 0) {
cout << -1 << '\n';
return 0;
}
V<int> ans;
int lb = 0;
while (M != 0) {
int arg = -1;
for (int i = lb; i < N; i++) {
// A_iを使ってMを作れるか
if (M - A[i] < 0) continue;
if (dp[i + 1][M - A[i]] == 1) {
if (arg == -1) {
arg = i;
} else if (P[arg] > P[i]) {
arg = i;
}
}
}
assert(arg != -1);
ans.push_back(arg);
lb = arg + 1;
M -= A[arg];
}
cout << ans.size() << '\n';
rep(i, ans.size()) cout << ans[i] + 1 << (i == ans.size() - 1 ? '\n' : ' ');
show(ans);
return 0;
}