結果

問題 No.1872 Dictionary Order
ユーザー se1ka2
提出日時 2022-03-11 22:22:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 73,472 KB
実行使用メモリ 31,488 KB
最終ジャッジ日時 2024-09-16 02:43:29
合計ジャッジ時間 7,217 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int a[2003], p[2003];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
    }
    vector<int> dp[2003];
    vector<int> ans[2003];
    for(int i = 1; i <= m; i++) dp[i] = {n};
    for(int i = 0; i < n; i++){
        for(int j = m; j >= a[i]; j--){
            if(dp[j] > dp[j - a[i]]){
                dp[j] = dp[j - a[i]];
                dp[j].push_back(p[i]);
                ans[j] = ans[j - a[i]];
                ans[j].push_back(i);
            }
        }
    }
    if(ans[m].size()){
        cout << ans[m].size() << endl;
        for(int i : ans[m]) cout << i + 1 << " ";
        cout << endl;
    }
    else{
        cout << -1 << endl;
    }
}
0