結果

問題 No.3459 Defeat Slimes
コンテスト
ユーザー tyawanmusi
提出日時 2026-02-27 11:09:02
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 1,931 ms / 3,000 ms
コード長 913 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 802 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 67,732 KB
最終ジャッジ日時 2026-02-28 13:14:12
合計ジャッジ時間 48,324 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())
clx = [tuple(map(int, input().split())) for _ in range(n)]
clx.sort(key=lambda x: x[1])
clx.append((1, 10**18+1, 1))
h = []
for i in range(n):
    if clx[i][1] <= y:
        heappush(h, (-clx[i][2], clx[i][0]))
    else:
        break
ans = 0
while y < z:
    nxtl = clx[i][1]
    if h:
        x, c = heappop(h)
        x = -x
        if y + c * x >= z and z <= nxtl + x:
            ans += (z - y + x - 1) // x
            print(ans)
            exit()
        if y + c * x < nxtl:
            ans += c
            y += c * x
        else:
            ans += (nxtl - y + x - 1) // x
            y += ((nxtl - y + x - 1) // x) * x
            heappush(h, (-x, c - (nxtl - y + x - 1) // x))
    else:
        print(-1)
        exit()
    # print(y, ans,h)
    while clx[i][1] <= y:
        heappush(h, (-clx[i][2], clx[i][0]))
        i += 1
0