結果
問題 |
No.37 遊園地のアトラクション
|
ユーザー |
![]() |
提出日時 | 2025-03-20 20:38:28 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 54 ms / 5,000 ms |
コード長 | 1,549 bytes |
コンパイル時間 | 217 ms |
コンパイル使用メモリ | 82,348 KB |
実行使用メモリ | 63,412 KB |
最終ジャッジ日時 | 2025-03-20 20:38:53 |
合計ジャッジ時間 | 2,409 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
import sys def main(): T = int(sys.stdin.readline()) N = int(sys.stdin.readline()) c = list(map(int, sys.stdin.readline().split())) v = list(map(int, sys.stdin.readline().split())) attractions = [] for i in range(N): current_c = c[i] current_v = v[i] options = [(0, 0)] current_time = current_c total_value = current_v if current_time <= T: options.append((current_time, total_value)) next_v = current_v // 2 while next_v > 0 and current_time + current_c <= T: current_time += current_c total_value += next_v options.append((current_time, total_value)) next_v = next_v // 2 sorted_options = sorted(options, key=lambda x: x[0]) pruned = [] max_val = -1 for t, val in sorted_options: if val > max_val: pruned.append((t, val)) max_val = val attractions.append(pruned) dp_prev = [-1] * (T + 1) dp_prev[0] = 0 for attraction in attractions: new_dp = [x for x in dp_prev] for t_opt, val_opt in attraction: for t in range(T, t_opt - 1, -1): if dp_prev[t - t_opt] != -1: if new_dp[t] < dp_prev[t - t_opt] + val_opt: new_dp[t] = dp_prev[t - t_opt] + val_opt dp_prev = new_dp max_val = max([v for v in dp_prev if v != -1]) print(max_val) if __name__ == "__main__": main()