結果

問題 No.59 鉄道の旅
ユーザー TawaraTawara
提出日時 2015-12-30 18:54:50
言語 Python2
(2.7.18)
結果
AC  
実行時間 710 ms / 5,000 ms
コード長 270 bytes
コンパイル時間 588 ms
コンパイル使用メモリ 6,564 KB
実行使用メモリ 21,736 KB
最終ジャッジ日時 2023-08-26 06:51:09
合計ジャッジ時間 4,500 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
21,496 KB
testcase_01 AC 30 ms
21,424 KB
testcase_02 AC 33 ms
21,416 KB
testcase_03 AC 29 ms
21,352 KB
testcase_04 AC 579 ms
21,736 KB
testcase_05 AC 32 ms
21,364 KB
testcase_06 AC 33 ms
21,536 KB
testcase_07 AC 33 ms
21,488 KB
testcase_08 AC 96 ms
21,412 KB
testcase_09 AC 86 ms
21,364 KB
testcase_10 AC 96 ms
21,500 KB
testcase_11 AC 80 ms
21,432 KB
testcase_12 AC 533 ms
21,524 KB
testcase_13 AC 617 ms
21,640 KB
testcase_14 AC 710 ms
21,632 KB
testcase_15 AC 30 ms
21,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int,raw_input().split());M=10**6+1;B=[0]*M;C=[0]*M
def A(a,w):
	while a<M:B[a]+=w;a+=a&(-a)
def S(a):
	r=0
	while a>0:r+=B[a];a-=a&(-a)
	return r
while N:
	N-=1;w=input()
	if w>0:
		if S(M-w)<K:A(M-w,1);C[w]+=1
	else:
		if C[-w]>0:A(M+w,-1);C[-w]-=1
print S(M-1)
0