結果

問題 No.817 Coin donation
ユーザー c-yanc-yan
提出日時 2021-01-18 03:30:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 497 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 62,096 KB
最終ジャッジ日時 2023-08-20 09:59:10
合計ジャッジ時間 3,282 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,288 KB
testcase_01 AC 17 ms
8,088 KB
testcase_02 AC 17 ms
8,252 KB
testcase_03 AC 17 ms
8,256 KB
testcase_04 AC 17 ms
8,164 KB
testcase_05 AC 26 ms
9,892 KB
testcase_06 AC 65 ms
15,860 KB
testcase_07 AC 75 ms
17,248 KB
testcase_08 AC 325 ms
40,684 KB
testcase_09 AC 89 ms
18,288 KB
testcase_10 AC 460 ms
62,096 KB
testcase_11 AC 471 ms
61,908 KB
testcase_12 AC 497 ms
62,000 KB
testcase_13 AC 16 ms
8,148 KB
testcase_14 AC 17 ms
8,120 KB
testcase_15 AC 16 ms
8,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
from itertools import accumulate

readline = stdin.readline

N, K = map(int, readline().split())
AB = [tuple(map(int, readline().split())) for _ in range(N)]

p = set()
for a, b in AB:
    p.add(a)
    p.add(b + 1)
inv = sorted(p)
fwd = {}
for i in range(len(inv)):
    fwd[inv[i]] = i

t = [0] * len(inv)
for a, b in AB:
    t[fwd[a]] += 1
    t[fwd[b + 1]] -= 1
t = list(accumulate(t))

c = 0
for i in range(len(t)):
    x = c + t[i] * (inv[i + 1] - inv[i])
    if x < K:
        c = x
        continue
    print(inv[i] + (K - c - 1) // t[i])
    break
0