提出 #58342253


ソースコード 拡げる

def w a; warn a.inspect end

N,M,K,*A = $<.read.split.map(&:to_i)
if N==M
	puts [0]*N*' '
	exit
end
I = N.times.group_by{|i| A[i] }
A.sort!.reverse! # A[]: A[i] より大きい値を数えるカウンター
B = A[0,M] # B[-1]: X 票を M+1 人に分配したときの底が満たせないライン
S = A.inject([0]){|s,a| s<<s[-1]+a }
X = K-S[-1] # x の最大値
Xs = [nil]*N # 答え 
I.keys.sort.each{|a|
	A.pop while A[0] && A[-1]<=a
	sm1 = M<=A.size ? S[M]+a : S[M+1] # M+1 人の既得票
	B.pop while B[0] && B[-1]*(M+1-B.size)-(sm1-S[B.size])<=X
#w [a,A,B,sm1,M+1-B.size,sm1-S[B.size],X]
	x = if M<=A.size && M==B.size # X 票足して M 人目に届かない
			-1
		elsif A.size<B.size # X 票足して M 人が a に届かない(a に届くのが M 人に満たない)
			0
		else
			x = sm1-S[B.size]+X
			k = M+1-B.size
			# x 票を k 人で均等に分ける
			(x+1)/k-a
		end
	I[a].each{|i|
		Xs[i] = x
	}
}
puts Xs*' '

提出情報

提出日時
問題 E - How to Win the Election
ユーザ ds14050
言語 Ruby (ruby 3.2.2)
得点 500
コード長 970 Byte
結果 AC
実行時間 313 ms
メモリ 64500 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 2
AC × 43
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 02_hand_00.txt, 02_hand_01.txt, 02_hand_02.txt, 02_hand_03.txt, 02_hand_04.txt, 02_hand_05.txt, 02_hand_06.txt, 02_hand_07.txt, 02_hand_08.txt, 02_hand_09.txt, 02_hand_10.txt, 02_hand_11.txt, 03_large_k_00.txt, 03_large_k_01.txt, 03_large_k_02.txt, 03_large_k_03.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 110 ms 17128 KiB
00_sample_01.txt AC 43 ms 17148 KiB
01_random_00.txt AC 129 ms 29724 KiB
01_random_01.txt AC 186 ms 34144 KiB
01_random_02.txt AC 295 ms 61412 KiB
01_random_03.txt AC 260 ms 53248 KiB
01_random_04.txt AC 191 ms 34528 KiB
01_random_05.txt AC 299 ms 63812 KiB
01_random_06.txt AC 43 ms 17220 KiB
01_random_07.txt AC 43 ms 17192 KiB
01_random_08.txt AC 44 ms 17596 KiB
01_random_09.txt AC 45 ms 17368 KiB
01_random_10.txt AC 46 ms 17612 KiB
01_random_11.txt AC 45 ms 17476 KiB
01_random_12.txt AC 312 ms 63576 KiB
01_random_13.txt AC 298 ms 63784 KiB
01_random_14.txt AC 291 ms 64392 KiB
01_random_15.txt AC 300 ms 61912 KiB
01_random_16.txt AC 299 ms 64500 KiB
01_random_17.txt AC 297 ms 63424 KiB
01_random_18.txt AC 313 ms 64256 KiB
01_random_19.txt AC 300 ms 63852 KiB
01_random_20.txt AC 215 ms 47436 KiB
01_random_21.txt AC 217 ms 47128 KiB
01_random_22.txt AC 216 ms 50712 KiB
01_random_23.txt AC 215 ms 46916 KiB
01_random_24.txt AC 213 ms 46792 KiB
02_hand_00.txt AC 169 ms 43840 KiB
02_hand_01.txt AC 170 ms 44052 KiB
02_hand_02.txt AC 169 ms 43652 KiB
02_hand_03.txt AC 162 ms 43760 KiB
02_hand_04.txt AC 168 ms 44056 KiB
02_hand_05.txt AC 163 ms 43720 KiB
02_hand_06.txt AC 175 ms 44540 KiB
02_hand_07.txt AC 178 ms 43888 KiB
02_hand_08.txt AC 161 ms 41564 KiB
02_hand_09.txt AC 171 ms 43908 KiB
02_hand_10.txt AC 173 ms 43328 KiB
02_hand_11.txt AC 115 ms 38204 KiB
03_large_k_00.txt AC 78 ms 22248 KiB
03_large_k_01.txt AC 72 ms 21320 KiB
03_large_k_02.txt AC 232 ms 50536 KiB
03_large_k_03.txt AC 56 ms 18752 KiB