結果

問題 No.37 遊園地のアトラクション
ユーザー koyopro
提出日時 2015-09-29 22:01:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 629 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 161,396 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-10 13:06:03
合計ジャッジ時間 2,178 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)

int T, N;
struct A { int c, v; };
vector<A> a;

int main()
{
    cin>>T>>N;
    REP(i,N) {
        A ai = A();
        cin >> ai.c;
        a.push_back(ai);
    }
    REP(i,N) cin >> a[i].v;
    int dp[20001] = {0};
    REP(i,N) {
        A ai = a[i];
        int v = ai.v;
        int c = ai.c;
        while(v > 0) {
            RREP(j,10001) {
                dp[j+c] = max(dp[j+c], dp[j] + v);
            }
            v /= 2;
        }
    }
    cout << dp[T] << endl;
    return 0;
}
0