結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー nebukuro09nebukuro09
提出日時 2016-11-21 10:07:10
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 1,735 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 101,972 KB
実行使用メモリ 19,828 KB
最終ジャッジ日時 2023-09-02 22:58:59
合計ジャッジ時間 6,288 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,372 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 AC 21 ms
5,672 KB
testcase_14 AC 24 ms
6,212 KB
testcase_15 AC 60 ms
13,232 KB
testcase_16 AC 100 ms
15,536 KB
testcase_17 AC 98 ms
13,144 KB
testcase_18 AC 18 ms
4,368 KB
testcase_19 AC 140 ms
19,828 KB
testcase_20 AC 49 ms
11,020 KB
testcase_21 AC 133 ms
15,028 KB
testcase_22 AC 49 ms
5,940 KB
testcase_23 AC 140 ms
17,328 KB
testcase_24 AC 37 ms
11,320 KB
testcase_25 AC 132 ms
7,720 KB
testcase_26 AC 18 ms
6,096 KB
testcase_27 AC 99 ms
13,152 KB
testcase_28 AC 99 ms
13,504 KB
testcase_29 AC 52 ms
6,696 KB
testcase_30 AC 149 ms
19,552 KB
testcase_31 AC 21 ms
4,368 KB
testcase_32 AC 22 ms
4,368 KB
testcase_33 AC 157 ms
19,172 KB
testcase_34 AC 147 ms
14,908 KB
testcase_35 AC 155 ms
17,516 KB
testcase_36 AC 145 ms
14,924 KB
testcase_37 AC 151 ms
12,684 KB
testcase_38 AC 147 ms
14,180 KB
権限があれば一括ダウンロードができます

ソースコード

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!(long, "t", long, "d") Task;
  auto input = readln.split;
  auto N = input[0].to!int;
  auto K = input[1].to!long;
  auto tasks = new Task[](N);
  foreach (i; 0..N) {
    input = readln.split;
    tasks[i] = Task(input[0].to!long, input[1].to!long);
  }
  
  long high = 10^^9;
  long 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;
  }

  long ans;

  long[] 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 long[](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