結果

問題 No.710 チーム戦
ユーザー しらっ亭しらっ亭
提出日時 2018-04-18 03:49:27
言語 Ruby
(3.3.0)
結果
AC  
実行時間 638 ms / 3,000 ms
コード長 437 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 11,312 KB
実行使用メモリ 15,524 KB
最終ジャッジ日時 2023-09-09 11:18:36
合計ジャッジ時間 10,840 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,012 KB
testcase_01 AC 78 ms
15,024 KB
testcase_02 AC 361 ms
15,284 KB
testcase_03 AC 365 ms
15,504 KB
testcase_04 AC 380 ms
15,328 KB
testcase_05 AC 358 ms
15,404 KB
testcase_06 AC 378 ms
15,304 KB
testcase_07 AC 342 ms
15,512 KB
testcase_08 AC 391 ms
15,500 KB
testcase_09 AC 352 ms
15,296 KB
testcase_10 AC 331 ms
15,416 KB
testcase_11 AC 360 ms
15,384 KB
testcase_12 AC 360 ms
15,516 KB
testcase_13 AC 352 ms
15,504 KB
testcase_14 AC 365 ms
15,472 KB
testcase_15 AC 349 ms
15,408 KB
testcase_16 AC 346 ms
15,364 KB
testcase_17 AC 366 ms
15,308 KB
testcase_18 AC 354 ms
15,480 KB
testcase_19 AC 371 ms
15,476 KB
testcase_20 AC 361 ms
15,372 KB
testcase_21 AC 374 ms
15,352 KB
testcase_22 AC 638 ms
15,488 KB
testcase_23 AC 77 ms
15,084 KB
testcase_24 AC 611 ms
15,524 KB
testcase_25 AC 77 ms
15,024 KB
testcase_26 AC 77 ms
15,144 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = []
B = []

sum_b = 0
N.times do
	a, b = gets.split.map(&:to_i)
	A.push(a)
	B.push(b)
	sum_b += b
end

aa = 0
bb = 0

N.times do |i|
	if aa < bb
		aa += A[i]
	else
		bb += B[i]
	end
end

ma = [aa, bb].max

dp = [0] * ma

N.times do |i|
	a = A[i]
	b = B[i]
	(ma-a-1).downto(0) do |j|
		dp[j + a] = [dp[j + a], dp[j] + b].max
	end
end

ans = ma
ma.times do |i|
	ans = [ans, [i, sum_b - dp[i]].max].min
end

puts(ans.to_s)
0