結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー nebukuro09nebukuro09
提出日時 2016-11-21 10:04:32
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,719 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 104,240 KB
実行使用メモリ 14,924 KB
最終ジャッジ日時 2023-09-02 22:58:49
合計ジャッジ時間 5,424 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;


void main() {
  alias Tuple!(int, "t", int, "d") Task;
  auto input = readln.split.map!(to!int);
  auto N = input[0];
  auto K = input[1];
  auto tasks = new Task[](N);
  foreach (i; 0..N) {
    input = readln.split.map!(to!int);
    tasks[i] = Task(input[0], input[1]);
  }
  
  int high = 10^^9;
  int low = -1;
  while (high - low > 1) {
    auto mid = (high - low) / 2 + low;
    auto last = -K-1;
    auto flag = true;
    foreach (task; tasks) {
      if (task.d > mid) {
        if (task.t - last < K) {
          flag = false;
          break;
        }
        else
          last = task.t;
      }
    }
    if (flag)
      high = mid;
    else
      low = mid;
  }

  int ans;

  int[] sleeps = [-K-1];
  foreach (task; tasks)
    if (task.d > high) 
      sleeps ~= task.t;
  sleeps ~= 10^^9 + K + 1;
  
  int last = 0;
  Task[] new_tasks;
  foreach (task; tasks) {
    if (task.d > high) {
      last += 1;
      ans += task.d;
    }
    else if (sleeps[last+1] - task.t >= K && task.t - sleeps[last] >= K)
      new_tasks ~= task;
  }

  auto M = new_tasks.length.to!int;
  auto dp = new int[](M);
  if (M == 0) {M += 1; dp ~= 0;}
  else {dp[0] = new_tasks[0].d;}
  last = -1;
  foreach (i; 1..M) {
    auto t = new_tasks[i].t;
    auto d = new_tasks[i].d;
    while (t - new_tasks[last+1].t >= K)
      last += 1;
    if (last >= 0)
      dp[i] = max(dp[i-1], dp[last]+d);
    else
      dp[i] = max(dp[i-1], d);
  }

  writeln(high);
  writeln(tasks.map!(t => t.d).sum - ans - dp[M-1]);

}
0