結果

問題 No.3761 Moonlit Battle
コンテスト
ユーザー ei1333333
提出日時 2026-10-04 20:00:53
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 737 ms / 2,000 ms
+ 56µs
コード長 540 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 82 ms
コンパイル使用メモリ 64,384 KB
実行使用メモリ 102,476 KB
最終ジャッジ日時 2026-10-30 12:53:06
合計ジャッジ時間 10,381 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N, D = map(int, input().split())

V = []
total = 0

for _ in range(N):
    a, b = map(int, input().split())
    V.append((b, a))
    total += a

V.sort(reverse=True)

K = min(D, total)

base = 0
cur = 0
events = {}

for b, a in V:
    take = min(a, K)
    if take == 0:
        break

    base += take * (b // D)

    r = b % D
    if r != 0:
        events[r] = events.get(r, 0) + take
        cur += take

    K -= take

add = cur

for r in sorted(events):
    cnt = events[r]
    cur -= cnt
    add = min(add, r + cur)

print(base + add)
0