結果

問題 No.3329 Only the Rightest Choice is Right!!!
コンテスト
ユーザー のらら
提出日時 2025-08-09 14:11:59
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 93 ms / 1,571 ms
コード長 875 bytes
コンパイル時間 3,048 ms
コンパイル使用メモリ 177,252 KB
実行使用メモリ 74,368 KB
最終ジャッジ日時 2025-11-02 16:29:53
合計ジャッジ時間 8,228 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 74
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
//#define endl "\n";
const long long INF = 1000000000000000000;
ll N, W, v[3009], w[3009];
ll dp[3009][3009];

int main(){
  cin >> N >> W;
  for(int i = 1; i <= N; i++) cin >> v[i];
  for(int i = 1; i <= N; i++) cin >> w[i];
  for(int i = N; i >= 1; i--){
    for(int j = 0; j <= W; j++){
      dp[i - 1][j] = max(dp[i - 1][j], dp[i][j]);
      if(j + w[i] <= W){
        dp[i - 1][j + w[i]] = max(dp[i - 1][j + w[i]], dp[i][j] + v[i]);
      }
    }
  }
  
  ll pos = W;
  vector<ll> ans;
  for(int i = 0; i < N; i++){
    if(dp[i][pos] == dp[i + 1][pos]){
      continue;
    }else{
      ans.push_back(i + 1);
      pos -= w[i + 1];
    }
  }
  cout << ans.size() << endl;
  for(auto p: ans) cout << p << " ";
  cout << endl;
  return 0;
}
0