結果

問題 No.59 鉄道の旅
ユーザー szkhtsszkhts
提出日時 2024-03-24 08:17:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 650 ms / 5,000 ms
コード長 521 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 11,776 KB
実行使用メモリ 17,804 KB
最終ジャッジ日時 2024-03-24 08:17:33
合計ジャッジ時間 4,513 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
17,796 KB
testcase_01 AC 41 ms
17,796 KB
testcase_02 AC 41 ms
17,796 KB
testcase_03 AC 42 ms
17,796 KB
testcase_04 AC 555 ms
17,804 KB
testcase_05 AC 43 ms
17,796 KB
testcase_06 AC 42 ms
17,796 KB
testcase_07 AC 42 ms
17,796 KB
testcase_08 AC 99 ms
17,804 KB
testcase_09 AC 98 ms
17,804 KB
testcase_10 AC 100 ms
17,804 KB
testcase_11 AC 78 ms
17,804 KB
testcase_12 AC 377 ms
17,804 KB
testcase_13 AC 605 ms
17,804 KB
testcase_14 AC 650 ms
17,804 KB
testcase_15 AC 41 ms
17,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
MAX_W = 1000010
weights = [0] * (MAX_W + 1)
bit = 0

def sum_w(i):
    s = 0
    while(i > 0):
        s += weights[i]
        i -= i & -i
        
    return s

def add_w(i, x):
    while(i <= MAX_W):
        weights[i] += x
        i += i & -i
        
for i in range(n):
    w = int(input())
    if w > 0:
        if sum_w(MAX_W) - sum_w(w - 1) < k:
            add_w(w, 1)
    else:
        if sum_w(-w) - sum_w(-w - 1) >= 1:
            add_w(-w, -1)
            
print(sum_w(MAX_W))
0