結果

問題 No.3329 Only the Rightest Choice is Right!!!
コンテスト
ユーザー Rumain831
提出日時 2026-08-29 10:34:41
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 29 ms / 1,571 ms
+ 447µs
コード長 699 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,170 ms
コンパイル使用メモリ 176,332 KB
実行使用メモリ 38,912 KB
最終ジャッジ日時 2026-08-29 10:34:48
合計ジャッジ時間 6,846 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 74
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
using namespace std;
void chmax(int& a, int b){a=max(a, b);}

int main(void){
  int n, W; cin >> n >> W;
  vector<int> v(n), w(n);
  for(auto&x:v) cin >> x;
  for(auto&x:w) cin >> x;
  vector dp(n+1, vector<int>(W+1));
  for(int i=n-1; i>=0; i--){
    for(int j=0; j<=W; j++){
      chmax(dp[i][j], dp[i+1][j]);
      if(j>=w[i]&&dp[i+1][j-w[i]]>=0){
        chmax(dp[i][j], dp[i+1][j-w[i]]+v[i]);
      }
    }
  }
  int mv=dp[0][W], nw=W;
  vector<int> ans;
  for(int i=0; i<n; i++){
    if(dp[i][nw]==dp[i+1][nw]) continue;
    ans.push_back(i+1);
    nw-=w[i];
  }
  cout << ans.size() << endl;
  for(auto p:ans) cout << p << ' '; cout << endl;
  return 0; 
}
0