結果

問題 No.817 Coin donation
ユーザー Yukino DX.Yukino DX.
提出日時 2023-11-17 20:34:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 757 ms / 2,000 ms
コード長 531 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 64,852 KB
最終ジャッジ日時 2023-11-17 20:34:24
合計ジャッジ時間 5,071 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
9,984 KB
testcase_01 AC 28 ms
9,984 KB
testcase_02 AC 29 ms
9,984 KB
testcase_03 AC 39 ms
9,984 KB
testcase_04 AC 29 ms
9,984 KB
testcase_05 AC 44 ms
11,520 KB
testcase_06 AC 101 ms
17,092 KB
testcase_07 AC 135 ms
18,732 KB
testcase_08 AC 490 ms
45,752 KB
testcase_09 AC 142 ms
20,156 KB
testcase_10 AC 757 ms
64,852 KB
testcase_11 AC 720 ms
64,852 KB
testcase_12 AC 751 ms
64,852 KB
testcase_13 AC 29 ms
9,984 KB
testcase_14 AC 28 ms
9,984 KB
testcase_15 AC 28 ms
9,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict as dd

n, k = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]

cnts = dd(int)
for a, b in ab:
    cnts[a] += 1
    cnts[b + 1] -= 1

cnt = 0
acc = 0
cnts = [(key, val) for key, val in sorted(cnts.items())]
m = len(cnts)
for i in range(m - 1):
    acc += cnts[i][1]
    if cnt + acc * (cnts[i + 1][0] - cnts[i][0]) > k:
        ans = cnts[i][0] + (k - cnt + acc - 1) // acc - 1
        print(ans)
        exit()

    cnt += acc * (cnts[i + 1][0] - cnts[i][0])
0