結果

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;

const int  N = 140;
const int V = 501 * N;
int b[N];
int v[N];

int cc[16];
int vv[16];
int dp[N][V];

int main(void){
  int t, n;
  cin >> t >> n;
  REP(i, 0, n) {
    cin >> cc[i];
  }
  REP(i, 0, n) {
    cin >> vv[i];
  }
  int c = 0;
  REP(i, 0, n) {
    int q = vv[i];
    while (q > 0) {
      b[c] = cc[i];
      v[c] = q;
      q /= 2;
      ++c;
    }
  }
  REP(j, 0, V) {
    dp[0][j] = 0;
  }
  REP(i, 1, c + 1) {
    REP(j, 0, V) {
      int ma = 0;
      ma = dp[i - 1][j];
      if (j >= b[i - 1]) {
	ma = max(ma, dp[i - 1][j - b[i - 1]] + v[i - 1]);
      }
      if (j >= 1) {
	ma = max(ma, dp[i][j - 1]);
      }
      dp[i][j] = ma;
    }
  }
  cout << dp[c][t] << endl;
}
0