結果

問題 No.37 遊園地のアトラクション
ユーザー pessimist
提出日時 2025-06-15 06:36:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 623 bytes
コンパイル時間 1,576 ms
コンパイル使用メモリ 165,876 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-15 06:36:19
合計ジャッジ時間 2,667 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); 
    int N, T; cin>>T>>N;
    vector<int> c(N), v(N);
    for(int i=0;i<N;++i){
        cin>>c[i];
    }
    for(int i=0;i<N;++i){
        cin>>v[i];
    }

    const int INF=1e9;
    vector<int> dp(T+1, -INF);
    dp[0]=0;
    for(int i=0;i<N;++i){
        int val=v[i];
        while(val){
            for(int j=T;j>=c[i];--j){
                dp[j]=max(dp[j],dp[j-c[i]]+val);
            }
            val>>=1;
        }
    }
    cout<<*max_element(dp.begin(),dp.end())<<endl;
    return 0;
}
0