結果

問題 No.37 遊園地のアトラクション
ユーザー srjywrdnprkt
提出日時 2022-12-19 23:59:01
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 952 bytes
コンパイル時間 1,127 ms
コンパイル使用メモリ 144,748 KB
実行使用メモリ 14,976 KB
最終ジャッジ日時 2024-11-18 01:31:04
合計ジャッジ時間 2,328 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>

using namespace std;

int main(){

    long long T, N, x, mx=0;
    cin >> T >> N;
    vector<long long> c(N), v(N);
    for (int i=0; i<N; i++) cin >> c[i];
    for (int j=0; j<N; j++) cin >> v[j];
    for (int i=0; i<N; i++){
        x = v[i];
        while(x != 0){
            c.push_back(c[i]);
            v.push_back(x/2);
            x /= 2;
        }
    }
    N = c.size();
    vector<vector<long long>> dp(N+1, vector<long long>(T+1));

    for (int i=1; i<=N; i++){
        for (int j=0; j<=T; j++){
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if (j-c[i-1]>=0) dp[i][j] = max(dp[i][j], dp[i-1][j-c[i-1]]+v[i-1]);
        }
    }

    for (int i=0; i<=T; i++) mx = max(mx, dp[N][i]);
    cout << mx << endl;

    return 0;
}
0