結果
問題 | No.37 遊園地のアトラクション |
ユーザー |
|
提出日時 | 2024-10-24 03:21:04 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 608 bytes |
コンパイル時間 | 2,064 ms |
コンパイル使用メモリ | 202,496 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-24 03:21:08 |
合計ジャッジ時間 | 3,480 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;const int INF = 1 << 29;int dp[10001];int main(){cin.tie(nullptr)->sync_with_stdio(false);int W; cin >> W;int N; cin >> N;vector<int> wt(N), val(N);for(int i = 0; i < N; ++i){cin >> wt[i];}for(int i = 0; i < N; ++i){cin >> val[i];}memset(dp, -INF, sizeof(dp));dp[0] = 0;for(int i = 0; i < N; ++i){int vl = val[i];while(vl){for(int x = W; x >= wt[i]; --x){dp[x] = max(dp[x], dp[x - wt[i]] + vl);}vl >>= 1;}}cout << *max_element(dp, dp + W + 1) << endl;return 0;}