結果

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

ソースコード

diff #
raw source code

from heapq import heappush, heappop

N, Y, Z = map(int, input().split())
slime = [list(map(int, input().split())) for _ in range(N)]

slime.sort(key=lambda x:x[1])
idx = 0
que = []
ans = 0
while Y < Z and idx < N:
    while idx < N and slime[idx][1] <= Y:
        heappush(que, (-slime[idx][2], slime[idx][0]))
        idx += 1
    nex = Z
    if idx < N:
        nex = min(nex, slime[idx][1])
    while Y < nex and que:
        x, c = heappop(que)
        x = -x
        if Y+x*c <= nex:
            Y += x*c
            ans += c
        else:
            diff = nex-Y
            nc = (diff+x-1)//x
            c -= nc
            Y += x*nc
            ans += nc
            if c:
                heappush(que, (-x, c))
    if Y < nex:
        break

print(ans if Z <= Y else -1)
0