結果

問題 No.59 鉄道の旅
ユーザー yuki2006yuki2006
提出日時 2014-11-05 22:37:07
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 540 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 6,692 KB
実行使用メモリ 6,156 KB
最終ジャッジ日時 2023-08-26 05:18:32
合計ジャッジ時間 2,441 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,056 KB
testcase_01 AC 11 ms
5,996 KB
testcase_02 AC 11 ms
6,048 KB
testcase_03 AC 12 ms
6,156 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 36 ms
6,004 KB
testcase_12 AC 260 ms
5,920 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 11 ms
5,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

MX = 10000
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:
        if BIT_Sum(MX - W) < K:
            BIT_Add(MX - W, 1)
    elif W < 0:
        if BIT_Sum(MX + W) - BIT_Sum(MX + W - 1) > 0:
            BIT_Add(MX + W, -1)

print BIT_Sum(MX)
0