結果

問題 No.37 遊園地のアトラクション
ユーザー te-sh
提出日時 2017-01-17 15:28:35
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 660 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 145,796 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-12 06:27:21
合計ジャッジ時間 1,558 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto t = readln.chomp.to!int;
  auto n = readln.chomp.to!size_t;
  auto ci = readln.split.to!(int[]);
  auto vi = readln.split.to!(int[]);

  auto halfs(int v)
  {
    int[] vi;
    for (auto u = v / 2; u > 0; u /= 2) vi ~= u;
    return vi;
  }

  foreach (i; n.iota) {
    auto nvi = halfs(vi[i]);
    auto nci = new int[](nvi.length);
    nci[] = ci[i];
    ci ~= nci;
    vi ~= nvi;
  }

  n = ci.length;

  auto dp = new int[](t + 1);
  foreach (c, v; lockstep(ci, vi))
    foreach_reverse (i; c..t+1)
      dp[i] = max(dp[i], dp[i - c] + v);

  writeln(dp.reduce!max);
}
0