結果

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

ソースコード

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