結果

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

ソースコード

diff #
raw source code

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################

from collections import defaultdict
n, y, z = na()
c, l, x = zip(*[na() for i in range(n)])
idx = sorted(range(n), key = lambda x: l[x])
ans = 0
i = 0
from heapq import *
hq = []
L = []
for i in idx:
    if l[i] < z:
        L.append(l[i])
L.append(z)
i = 0

for z in L:
    while i < n and l[idx[i]] <= y:
        heappush(hq, (-x[idx[i]], c[idx[i]]))
        i += 1
    # print(hq, i, idx)
    while y < z and hq:
        xx, cc = heappop(hq)
        xx = -xx
        d = max(0, min(cc, (z - y - 1) // xx + 1))
        if d < cc:
            heappush(hq, (-xx, cc - d))
        ans += d
        y += xx * d
    # print(y, z, hq, ans)
    if y < z:
        print(-1)
        exit()

print(ans)
0