結果

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

ソースコード

diff #
raw source code

from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, groupby
from heapq import heappop, heappush
import math, sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
def printl(li, sep=" "): print(sep.join(map(str, li)))
def yn(flag): print(Yes if flag else No)
_int = lambda x: int(x)-1
MOD = 998244353 #10**9+7
INF = 1<<60
Yes, No = "Yes", "No"

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

LXC.sort(reverse=True)
q = []
def add():
    while LXC and LXC[-1][0] <= Y:
        l, x, c = LXC.pop()
        heappush(q, (-x, c))
add()
ans = 0
while q and Y < Z:
    x, c = heappop(q)
    x = -x
    if LXC:
        nxt = min(LXC[-1][0], Z)
    else:
        nxt = Z
    need = nxt-Y
    if need > x*c:
        ans += c
        Y += x*c
    else:
        cnt = -(-need//x)
        ans += cnt
        Y += x*cnt
        if c-cnt > 0:
            heappush(q, (-x, c-cnt))
    add()
print(ans if Y >= Z else -1)
0