結果

問題 No.1708 Quality of Contest
ユーザー 小野寺健小野寺健
提出日時 2021-10-30 15:35:14
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 861 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 55,704 KB
最終ジャッジ日時 2024-04-16 16:23:05
合計ジャッジ時間 10,530 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
19,228 KB
testcase_01 AC 90 ms
12,288 KB
testcase_02 AC 90 ms
12,288 KB
testcase_03 AC 693 ms
13,312 KB
testcase_04 AC 1,795 ms
13,184 KB
testcase_05 AC 1,935 ms
12,928 KB
testcase_06 AC 559 ms
13,184 KB
testcase_07 AC 560 ms
13,056 KB
testcase_08 AC 89 ms
12,160 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:14: warning: assigned but unused variable - k
Syntax OK

ソースコード

diff #

N, M, X = gets.split(" ").map{|s| s.to_i}

A = Array.new(M) {Array.new}

N.times {
	a, b = gets.split(" ").map{|s| s.to_i}
	A[b-1] << a
}

A.each {|a|
	a.sort_by!{|x| -x}
}

k = gets.to_i
c = gets.split(" ").map{|s| s.to_i}

cnt = []
cpos = Array.new(M, 0)
same = []
diff = []
0.upto(M-1) {|j|
	diff << [A[j][0], j] if A[j].length > 0
}
diff.sort!.reverse!
c.max.times {
	sa, sb = same.length > 0 ? same[0] : [-Float::INFINITY, -1]
	da, db = diff.length > 0 ? diff[0] : [-Float::INFINITY, -1]
	
	if sa > da + X then
		same.shift
		cpos[sb] += 1
		if cpos[sb] < A[sb].length then
			same << [A[sb][cpos[sb]], sb]
			same.sort!.reverse!
		end
		cnt << sa
	else
		diff.shift
		cpos[db] += 1
		if cpos[db] < A[db].length 
			same << [A[db][cpos[db]], db]
			same.sort!.reverse!
		end
		cnt << da + X
	end
}

total = 0
c.each {|i|
	total += cnt[0,i].sum
}
puts total
0