結果

問題 No.649 ここでちょっとQK!
ユーザー 0918nobita
提出日時 2018-02-22 19:06:31
言語 Ruby
(3.4.1)
結果
TLE  
実行時間 -
コード長 552 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 19,744 KB
最終ジャッジ日時 2024-10-02 08:02:32
合計ジャッジ時間 7,719 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other AC * 12 TLE * 1 -- * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def selection_sort ary
	ary_with_index = ary.zip(0...ary.length)
	(0...ary.length).each{|ix|
		min = ary_with_index[ix..-1].min_by{|num, ix| num}
		ary_with_index[ix][0], ary_with_index[min[1]][0] = min[0], ary_with_index[ix][0]
	}
	ary_with_index.map{|num, ix| num}
end

q, k = gets.split.map(&:to_i)
s = []
q.times{
	if v = gets.split.map(&:to_i)[1] then
		if s == [] || v >= s[-1] then
			s.push(v)
		elsif v <= s[0] then
			s.unshift(v)
		else
			s.unshift(v)
			s = selection_sort(s)
		end
	else
		puts s.size >= k ? s.delete_at(k - 1) : -1
	end
}
0