結果

問題 No.3459 Defeat Slimes
コンテスト
ユーザー koheijkt
提出日時 2026-03-01 13:16:44
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 614 ms / 3,000 ms
コード長 867 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 219 ms
コンパイル使用メモリ 85,740 KB
実行使用メモリ 119,496 KB
最終ジャッジ日時 2026-03-01 13:17:16
合計ジャッジ時間 21,961 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
import heapq
from bisect import bisect_right

input = sys.stdin.readline

N, Y, Z = map(int, input().split())
C, L, X = [], [], []
for _ in range(N):
    c, l, x = map(int, input().split())
    C.append(c)
    L.append(l)
    X.append(x)

border = [(L[i], i) for i in range(N)]
border.append((Z, -1))
border.sort()

pq = []
for i in range(N):
    if L[i] <= Y:
        heapq.heappush(pq, (-X[i], C[i]))

cur = Y
ans = 0
k = bisect_right(border, (cur, 1 << 60))

while pq and cur < Z:
    nxt, idx = border[k]
    if nxt <= cur:
        if idx != -1:
            heapq.heappush(pq, (-X[idx], C[idx]))
        k += 1
        continue

    x, c = heapq.heappop(pq)
    x = -x
    cnt = min((nxt - cur + x - 1) // x, c)
    cur += cnt * x
    ans += cnt
    if cnt != c:
        heapq.heappush(pq, (-x, c - cnt))

if cur < Z:
    print(-1)
else:
    print(ans)
0