結果

問題 No.3459 Defeat Slimes
コンテスト
ユーザー prd_xxx
提出日時 2026-02-28 14:49:04
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 899 ms / 3,000 ms
コード長 992 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 336 ms
コンパイル使用メモリ 77,808 KB
実行使用メモリ 122,088 KB
最終ジャッジ日時 2026-02-28 14:49:36
合計ジャッジ時間 25,520 ms
ジャッジサーバーID
(参考情報)
judge7 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline
N,Y,Z = map(int,input().split())
CLX = [tuple(map(int,input().split())) for _ in range(N)]

CLX.sort(key= lambda x:-x[1])

level = Y
import heapq
hq = []
while CLX and CLX[-1][1] <= level:
    c,l,x = CLX.pop()
    heapq.heappush(hq, (-x,c)) #倒すとlevel -x上昇, スライムc体

defeated = 0
while hq:
    x,c = heapq.heappop(hq)
    dl = -x
    next_slime_level = None
    if CLX:
        nc,next_slime_level,nx = CLX[-1]
    if next_slime_level is not None and level + c*dl >= next_slime_level:
        k = 0--(next_slime_level-level)//dl
        defeated += k
        level += k*dl
        rem = c-k
        if rem > 0:
            heapq.heappush(hq, (x,rem))
        while CLX and CLX[-1][1] <= level:
            c,l,x = CLX.pop()
            heapq.heappush(hq, (-x,c))
    elif level + c*dl >= Z:
        k = 0--(Z-level)//dl
        defeated += k
        exit(print(defeated))
    else:
        level += c*dl
        defeated += c
print(-1)
0