結果
| 問題 | No.3329 Only the Rightest Choice is Right!!! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-29 10:33:29 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 1,571 ms |
| + 409µs | |
| コード長 | 763 bytes |
| 記録 | |
| コンパイル時間 | 1,223 ms |
| コンパイル使用メモリ | 183,852 KB |
| 実行使用メモリ | 73,984 KB |
| 最終ジャッジ日時 | 2026-08-29 10:33:42 |
| 合計ジャッジ時間 | 6,166 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 74 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
using P = pair<int, int>;
void chmax(ll& a, ll 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<ll>(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]);
}
}
}
ll 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;
}