結果

問題 No.59 鉄道の旅
ユーザー pluto77pluto77
提出日時 2016-07-10 13:40:14
言語 Python2
(2.7.18)
結果
AC  
実行時間 484 ms / 5,000 ms
コード長 447 bytes
コンパイル時間 547 ms
コンパイル使用メモリ 6,728 KB
実行使用メモリ 21,724 KB
最終ジャッジ日時 2023-08-26 07:06:04
合計ジャッジ時間 4,346 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
21,560 KB
testcase_01 AC 106 ms
21,576 KB
testcase_02 AC 107 ms
21,668 KB
testcase_03 AC 105 ms
21,556 KB
testcase_04 AC 383 ms
21,724 KB
testcase_05 AC 106 ms
21,580 KB
testcase_06 AC 107 ms
21,672 KB
testcase_07 AC 106 ms
21,720 KB
testcase_08 AC 146 ms
21,540 KB
testcase_09 AC 135 ms
21,632 KB
testcase_10 AC 142 ms
21,672 KB
testcase_11 AC 122 ms
21,724 KB
testcase_12 AC 267 ms
21,544 KB
testcase_13 AC 388 ms
21,536 KB
testcase_14 AC 484 ms
21,624 KB
testcase_15 AC 103 ms
21,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding: utf-8
#yuki_059

n,k=map(int,raw_input().split())
bit=[0 for i in xrange(1000001)]
cnt=[0 for i in xrange(1000001)]

def sum(i):
 s=0
 while i>0:
  s+=bit[i]
  i-=i & (-i)
 return s
 
def add(i,x):
 while i<=1000000:
  bit[i]+=x
  i+=i & (-i)
  
total=0
for i in xrange(n):
 w=int(raw_input())
 if w>0:
  if total-sum(w-1)<k:
   add(w,1)
   cnt[w]+=1
   total+=1
 else:
  if cnt[-w]>0:
   add(-w,-1)
   cnt[-w]-=1
   total-=1
print total
0