結果

問題 No.37 遊園地のアトラクション
ユーザー pessimist
提出日時 2025-06-15 14:59:10
言語 C++17(gnu拡張)
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 663 bytes
コンパイル時間 2,225 ms
コンパイル使用メモリ 196,324 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-15 14:59:14
合計ジャッジ時間 3,610 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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];
        int ii=1;
        while(val){
            for(int j=T;j>=ii*c[i];--j){
                dp[j]=max(dp[j],dp[j-c[i]]+val);
            }
            val>>=1;
            ii+=1;
        }
    }
    cout<<*max_element(dp.begin(),dp.end())<<endl;
    return 0;
}
0