結果

問題 No.37 遊園地のアトラクション
ユーザー purple_jwlpurple_jwl
提出日時 2015-03-16 08:34:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 990 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 163,680 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 19:32:44
合計ジャッジ時間 2,784 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main() {
  // ios_base::sync_with_stdio(false);
  int T, N;
  cin >> T >> N;
  vector<int> c(N);
  vector<vector<int>> v(N);
  rep(i, N) cin >> c[i];
  rep(i, N) {
    int tmp;
    cin >> tmp;
    while(tmp) {
      v[i].push_back(tmp);
      tmp /= 2;
    }
  }
  vector<int> dp(T + 1, -1);
  dp[0] = 0;
  for(int j = 0; j < N; j++) {
    for(int k = 0; k < v[j].size(); k++) {
      for(int i = T; i >= 0; i--) {
        if(dp[i] == -1 || i + c[j] > T) continue;
        dp[i + c[j]] = max(dp[i + c[j]], dp[i] + v[j][k]);
      }
    }
  }
  int ans = 0;
  rep(i, T + 1) ans = max(ans, dp[i]);    
  cout << ans << endl;
  return 0;
}
0