結果

問題 No.817 Coin donation
ユーザー c-yanc-yan
提出日時 2021-02-13 06:51:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 664 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 60,704 KB
最終ジャッジ日時 2023-09-27 13:48:33
合計ジャッジ時間 3,446 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,236 KB
testcase_01 AC 14 ms
8,168 KB
testcase_02 AC 14 ms
8,220 KB
testcase_03 AC 14 ms
8,236 KB
testcase_04 AC 13 ms
8,288 KB
testcase_05 AC 22 ms
9,616 KB
testcase_06 AC 53 ms
14,644 KB
testcase_07 AC 63 ms
15,896 KB
testcase_08 AC 248 ms
40,344 KB
testcase_09 AC 74 ms
16,868 KB
testcase_10 AC 353 ms
60,632 KB
testcase_11 AC 363 ms
60,704 KB
testcase_12 AC 372 ms
60,584 KB
testcase_13 AC 15 ms
8,152 KB
testcase_14 AC 13 ms
8,236 KB
testcase_15 AC 13 ms
8,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
from itertools import accumulate

readline = stdin.readline


def shrink(a):
    inv = sorted(set(a))
    n = len(inv)
    fwd = {}
    for i in range(n):
        fwd[inv[i]] = i
    return n, fwd, inv


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

p = []
for a, b in AB:
    p.append(a)
    p.append(b + 1)
n, fwd, inv = shrink(p)

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

c = 0
for i in range(n):
    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