結果

問題 No.37 遊園地のアトラクション
ユーザー pessimist
提出日時 2024-10-24 03:21:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 608 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 195,468 KB
最終ジャッジ日時 2025-02-24 22:36:35
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0