結果

問題 No.59 鉄道の旅
ユーザー TawaraTawara
提出日時 2015-12-30 17:30:54
言語 Python2
(2.7.18)
結果
AC  
実行時間 797 ms / 5,000 ms
コード長 369 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 7,120 KB
実行使用メモリ 21,736 KB
最終ジャッジ日時 2023-08-26 06:49:48
合計ジャッジ時間 4,512 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
21,424 KB
testcase_01 AC 37 ms
21,560 KB
testcase_02 AC 36 ms
21,520 KB
testcase_03 AC 36 ms
21,500 KB
testcase_04 AC 644 ms
21,628 KB
testcase_05 AC 37 ms
21,500 KB
testcase_06 AC 36 ms
21,364 KB
testcase_07 AC 36 ms
21,524 KB
testcase_08 AC 116 ms
21,568 KB
testcase_09 AC 102 ms
21,360 KB
testcase_10 AC 110 ms
21,552 KB
testcase_11 AC 91 ms
21,536 KB
testcase_12 AC 584 ms
21,384 KB
testcase_13 AC 694 ms
21,716 KB
testcase_14 AC 797 ms
21,736 KB
testcase_15 AC 36 ms
21,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int,raw_input().split())
bitN=10**6;bit=[0]*(bitN+1);cnt=[0]*(bitN+1)
def bit_add(a,w):
	while a<=bitN:bit[a]+=w;a+=a&(-a)
def bit_sum(a):
	ret=0
	while a>0:ret+=bit[a];a-=a&(-a)
	return ret
for i in xrange(N):
	w=input()
	if w > 0:
		if bit_sum(bitN-w+1)<K:bit_add(bitN-w+1,1);cnt[w]+=1
	else:
		if cnt[-w]>0:bit_add(bitN+w+1,-1);cnt[-w]-=1
print bit_sum(bitN)
0