結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー mkawa2mkawa2
提出日時 2020-04-25 18:42:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 766 ms / 2,000 ms
コード長 2,895 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 78,912 KB
最終ジャッジ日時 2024-04-25 05:43:31
合計ジャッジ時間 14,041 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
11,136 KB
testcase_01 AC 32 ms
11,008 KB
testcase_02 AC 30 ms
11,008 KB
testcase_03 AC 31 ms
11,008 KB
testcase_04 AC 31 ms
11,008 KB
testcase_05 AC 31 ms
11,008 KB
testcase_06 AC 33 ms
11,392 KB
testcase_07 AC 32 ms
11,008 KB
testcase_08 AC 32 ms
11,008 KB
testcase_09 AC 32 ms
11,136 KB
testcase_10 AC 31 ms
11,008 KB
testcase_11 AC 32 ms
11,264 KB
testcase_12 AC 32 ms
11,136 KB
testcase_13 AC 109 ms
18,944 KB
testcase_14 AC 117 ms
19,768 KB
testcase_15 AC 240 ms
32,780 KB
testcase_16 AC 480 ms
53,220 KB
testcase_17 AC 357 ms
45,120 KB
testcase_18 AC 83 ms
17,920 KB
testcase_19 AC 657 ms
69,332 KB
testcase_20 AC 192 ms
26,500 KB
testcase_21 AC 538 ms
59,012 KB
testcase_22 AC 215 ms
27,464 KB
testcase_23 AC 581 ms
59,404 KB
testcase_24 AC 158 ms
24,068 KB
testcase_25 AC 565 ms
58,844 KB
testcase_26 AC 90 ms
17,536 KB
testcase_27 AC 425 ms
46,168 KB
testcase_28 AC 453 ms
50,188 KB
testcase_29 AC 232 ms
30,912 KB
testcase_30 AC 653 ms
67,260 KB
testcase_31 AC 90 ms
18,816 KB
testcase_32 AC 97 ms
19,584 KB
testcase_33 AC 717 ms
72,380 KB
testcase_34 AC 562 ms
62,428 KB
testcase_35 AC 766 ms
78,912 KB
testcase_36 AC 551 ms
62,704 KB
testcase_37 AC 656 ms
66,876 KB
testcase_38 AC 544 ms
62,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import *
from bisect import *
from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    def ok(m):
        pt = -inf
        mxd = dd[m]
        # Ameの最大難易度をmxdとする
        # Yukiに振る仕事(難易度がmxdより大きい仕事)だけをみたとき
        # 時間の間隔がk以上空いているかチェックする
        for t, d in td:
            if d <= mxd: continue
            if t - pt < k: return False
            pt = t
        return True

    inf = 10 ** 10
    n, k = MI()
    td = LLI(n)
    # Ameの難易度最大値を二分探索
    dd = [0] + sorted(set(d for t, d in td))
    # print(dd)
    l = -1
    r = len(dd)
    while l + 1 < r:
        m = (l + r) // 2
        if ok(m): r = m
        else: l = m
    mxd = dd[r]
    print(mxd)
    if r == 0:
        print(0)
        exit()
    # Ameの最大難易度mxd以内の仕事のうち、Yukiに渡せるものをできるだけ渡す
    # Yukiの確定している仕事時刻を集計
    ytt = [t for t, d in td if d > mxd]
    # Ameの仕事のうち、Yukiの仕事から時間がk以上離れているものを集める
    # ついでにAmeの難易度合計totも計算
    tot = 0
    i = 0
    cando = []
    for t, d in td:
        if d > mxd: continue
        tot += d
        while i < len(ytt) - 1 and t > ytt[i] + k: i += 1
        if abs(t - ytt[i]) >= k: cando.append((t, d))
    # candoの中から、AmeからYukiに渡す仕事の難易度合計の最大値mxを求める
    # DPみたいな感じで
    # 時間順に見ていって、k時間以上前の最大難易度premaxに今の難易度を足していく
    premax = 0
    # 処理の終わった、時刻と合計難易度をttとsdに入れていく
    tt = [-inf]
    sd = [0]
    mx = 0
    i = 0
    for t, d in cando:
        # 時刻tからk以上離れている合計難易度の最大値を作る
        while i < len(tt) and tt[i] <= t - k:
            premax = max(premax, sd[i])
            i += 1
        # この仕事をやるときの最大難易度cur
        cur = premax + d
        tt.append(t)
        sd.append(cur)
        mx = max(mx, cur)
    # totのうちmxをYukiに渡すので、引き算するとAmeの難易度合計
    print(tot - mx)

main()
0