提出 #31310696
ソースコード 拡げる
class BIT
def initialize n
@a = [0]*(n+1) # 1-indexed internally
end
def [] i
i += 1
s = 0
while 0<i
s += @a[i]
i &= i-1
end
return s
end
def lb s
z = @a.size-1
i,t,b = 0,0,1<<z.bit_length
t += @a[i|=b] if i|b<=z && t+@a[i|b]<s while 0<b >>= 1
return i if i<z # i は1大きい内部インデックス(もしくは 0)だけど、求めた添字が s 未満の値を返す最大の添字であり、s の lower_bound としては +1 したものを返したいから、足し引きして内部インデックスそのままの値を返す(アクセス可能な範囲(0..z-1)なら)。
end
def add i,d
i += 1
while i<@a.size
@a[i] += d
i += i&-i
end
end
end
TY = $<.map{|ln| ln.split.map(&:to_i) }
(N,K),TY[0] = TY[0],[1,0]
TY.sort_by{-_2}.each_with_index{|ty,j| ty<<j }
x = -1.0/0
k = K
ps = ng = 0
NgS = BIT.new N+1
NgI = BIT.new N+1
TY.reverse_each{|t,y,j|
if t<2
y += ps
y -= NgS[NgI.lb ng-k] if k<ng
x = y if x<y
break if 0>k -= 1
elsif y<0
ng += 1
NgI.add j,1
NgS.add j,-y
else
ps += y
end
}
p x
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Ignore Operations |
| ユーザ | ds14050 |
| 言語 | Ruby (2.7.1) |
| 得点 | 500 |
| コード長 | 1130 Byte |
| 結果 | AC |
| 実行時間 | 520 ms |
| メモリ | 32768 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example_00.txt, example_01.txt, example_02.txt |
| All | example_00.txt, example_01.txt, example_02.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| example_00.txt | AC | 57 ms | 14364 KiB |
| example_01.txt | AC | 58 ms | 14152 KiB |
| example_02.txt | AC | 56 ms | 13972 KiB |
| test_00.txt | AC | 295 ms | 32768 KiB |
| test_01.txt | AC | 520 ms | 31496 KiB |
| test_02.txt | AC | 70 ms | 14936 KiB |
| test_03.txt | AC | 77 ms | 14960 KiB |
| test_04.txt | AC | 66 ms | 14984 KiB |
| test_05.txt | AC | 185 ms | 21716 KiB |
| test_06.txt | AC | 446 ms | 32264 KiB |
| test_07.txt | AC | 460 ms | 32160 KiB |
| test_08.txt | AC | 142 ms | 19032 KiB |
| test_09.txt | AC | 376 ms | 28916 KiB |
| test_10.txt | AC | 100 ms | 16228 KiB |
| test_11.txt | AC | 103 ms | 17240 KiB |
| test_12.txt | AC | 106 ms | 17400 KiB |
| test_13.txt | AC | 280 ms | 28148 KiB |
| test_14.txt | AC | 172 ms | 20652 KiB |
| test_15.txt | AC | 226 ms | 22112 KiB |
| test_16.txt | AC | 193 ms | 20164 KiB |
| test_17.txt | AC | 105 ms | 17032 KiB |
| test_18.txt | AC | 336 ms | 27152 KiB |
| test_19.txt | AC | 326 ms | 26292 KiB |
| test_20.txt | AC | 201 ms | 25640 KiB |
| test_21.txt | AC | 300 ms | 32100 KiB |
| test_22.txt | AC | 61 ms | 14444 KiB |
| test_23.txt | AC | 278 ms | 30160 KiB |
| test_24.txt | AC | 61 ms | 14456 KiB |
| test_25.txt | AC | 180 ms | 22044 KiB |
| test_26.txt | AC | 196 ms | 22228 KiB |
| test_27.txt | AC | 374 ms | 28044 KiB |
| test_28.txt | AC | 273 ms | 22908 KiB |