結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー te-shte-sh
提出日時 2017-12-21 18:35:28
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 97,476 KB
実行使用メモリ 7,488 KB
最終ジャッジ日時 2023-09-03 17:45:38
合計ジャッジ時間 4,648 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 15 ms
4,380 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 39 ms
6,208 KB
testcase_16 AC 65 ms
6,692 KB
testcase_17 AC 66 ms
6,432 KB
testcase_18 AC 12 ms
4,380 KB
testcase_19 AC 87 ms
7,232 KB
testcase_20 AC 32 ms
5,904 KB
testcase_21 AC 87 ms
7,240 KB
testcase_22 AC 33 ms
5,888 KB
testcase_23 AC 89 ms
7,216 KB
testcase_24 AC 23 ms
4,396 KB
testcase_25 AC 88 ms
7,192 KB
testcase_26 AC 12 ms
4,380 KB
testcase_27 AC 65 ms
6,140 KB
testcase_28 AC 60 ms
6,136 KB
testcase_29 AC 35 ms
5,908 KB
testcase_30 AC 90 ms
7,252 KB
testcase_31 AC 14 ms
5,612 KB
testcase_32 AC 16 ms
4,376 KB
testcase_33 AC 97 ms
7,480 KB
testcase_34 AC 95 ms
7,408 KB
testcase_35 AC 96 ms
7,480 KB
testcase_36 AC 91 ms
7,460 KB
testcase_37 AC 97 ms
7,488 KB
testcase_38 AC 95 ms
7,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.typecons;  // Tuple, Nullable, BigFlags

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], k = rd[1];
  auto t = new int[](n), d = new long[](n);
  foreach (i; 0..n) {
    auto rd2 = readln.splitter;
    t[i] = rd2.front.to!int; rd2.popFront();
    d[i] = rd2.front.to!long;
  }

  auto canSolve(long x)
  {
    auto prev = -k.to!long;
    foreach (i; 0..n)
      if (d[i] > x) {
        if (t[i] - prev < k) {
          return false;
        } else {
          prev = t[i];
        }
      }
    return true;
  }

  auto bsearch = iota(d.maxElement+1).map!(x => tuple(x, canSolve(x))).assumeSorted!"a[1]<b[1]";
  auto dm = bsearch.upperBound(tuple(0, false)).front[0];

  writeln(dm);

  auto dp = new long[](n+1), prev = -k.to!long;
  foreach (i; 0..n) {
    auto j = t.assumeSorted.lowerBound(t[i]-k+1).length;
    if (d[i] > dm) {
      dp[i+1] = d[i] + dp[j];
      prev = t[i];
    } else {
      if (t[i] - prev < k) {
        dp[i+1] = dp[i];
      } else {
        dp[i+1] = max(dp[i], d[i] + dp[j]);
      }
    }
  }

  writeln(d.sum - dp[n]);
}
0