結果
問題 |
No.37 遊園地のアトラクション
|
ユーザー |
|
提出日時 | 2024-10-03 12:56:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 5,000 ms |
コード長 | 718 bytes |
コンパイル時間 | 1,426 ms |
コンパイル使用メモリ | 168,148 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-03 12:56:38 |
合計ジャッジ時間 | 2,349 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
# include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 20; const int N = 10010; ll T, n; ll c[M], h[M]; ll dp[M][N]; int main() { scanf("%lld%lld", &T, &n); for (int i = 1; i <= n; i++) scanf("%lld", &c[i]); for (int i = 1; i <= n; i++) scanf("%lld", &h[i]); for (int i = 1; i <= n; i++) { for (int j = 0; j <= T; j++) { ll piou, fan; piou = h[i]; fan = 0; dp[i][j] = dp[i - 1][j]; for (int k = 1; k <= log2(h[i]) + 1; k++) { fan += piou; if (j >= k * c[i]) dp[i][j] = max(dp[i][j], dp[i - 1][j - k * c[i]] + fan); piou /= 2; } } } ll ans; ans = 0; for (int i = 0; i <= T; i++) ans = max(ans, dp[n][i]); printf("%lld\n", ans); return 0; }