結果

問題 No.59 鉄道の旅
ユーザー yuki2006yuki2006
提出日時 2014-11-05 22:53:19
言語 Python2
(2.7.18)
結果
AC  
実行時間 465 ms / 5,000 ms
コード長 578 bytes
コンパイル時間 1,038 ms
コンパイル使用メモリ 6,596 KB
実行使用メモリ 13,608 KB
最終ジャッジ日時 2023-08-26 05:18:59
合計ジャッジ時間 3,058 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
13,564 KB
testcase_01 AC 23 ms
13,532 KB
testcase_02 AC 23 ms
13,568 KB
testcase_03 AC 23 ms
13,608 KB
testcase_04 AC 448 ms
13,364 KB
testcase_05 AC 23 ms
13,476 KB
testcase_06 AC 24 ms
13,460 KB
testcase_07 AC 24 ms
13,408 KB
testcase_08 AC 67 ms
13,368 KB
testcase_09 AC 70 ms
13,516 KB
testcase_10 AC 71 ms
13,460 KB
testcase_11 AC 48 ms
13,464 KB
testcase_12 AC 270 ms
13,380 KB
testcase_13 AC 454 ms
13,560 KB
testcase_14 AC 465 ms
13,444 KB
testcase_15 AC 23 ms
13,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, raw_input().split())

MX = 1000000
data = [0] * (MX + 1)


def BIT_Add(x, a):
    while x <= MX:
        data[x] += a
        x += x & (-x)


def BIT_Sum(x):
    total = 0
    while x > 0:
        total += data[x]
        x -= x & (-x)
    return total


for _ in xrange(N):
    W = int(raw_input())

    if W > 0:
        W -= 1
        if BIT_Sum(MX - W) < K:
            BIT_Add(MX - W, 1)
    elif W < 0:
        W += 1

        if BIT_Sum(MX + W) - BIT_Sum(MX + W - 1) > 0:
            BIT_Add(MX + W, -1)

print BIT_Sum(MX)
0