結果

問題 No.904 サメトロ
ユーザー TANIGUCHI KousukeTANIGUCHI Kousuke
提出日時 2019-12-06 19:39:43
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 432 bytes
コンパイル時間 61 ms
コンパイル使用メモリ 11,248 KB
実行使用メモリ 15,420 KB
最終ジャッジ日時 2023-08-25 03:14:31
合計ジャッジ時間 5,927 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
15,300 KB
testcase_01 WA -
testcase_02 AC 98 ms
15,252 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 78 ms
15,260 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 78 ms
15,192 KB
testcase_19 WA -
testcase_20 AC 78 ms
15,036 KB
testcase_21 WA -
testcase_22 AC 101 ms
15,156 KB
testcase_23 AC 81 ms
15,080 KB
testcase_24 AC 90 ms
15,088 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 145 ms
15,312 KB
testcase_28 AC 81 ms
15,316 KB
testcase_29 AC 80 ms
15,176 KB
testcase_30 AC 80 ms
15,056 KB
testcase_31 WA -
testcase_32 AC 81 ms
15,256 KB
testcase_33 AC 81 ms
15,264 KB
testcase_34 AC 80 ms
15,156 KB
testcase_35 AC 82 ms
15,136 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# a + sumA = b + sumB
# a <= sumB, b <= sumA
# b - a = sumA - sumB
# max_{i \in N} (A_i + B_i - sumB) <= b

N = gets.to_i
A = Array.new(N - 1,0)
B = Array.new(N - 1,0)

(N-1).times do |i|
  a, b = gets.split.map(&:to_i)
  A[i] = a
  B[i] = b
end
sumA = A.sum
sumB= B.sum

b_min = (N - 1).times.inject(0) do |max,i|
  A[i] + B[i] - sumB
end

ans = (b_min .. sumA).count do |b|
  a = b - sumA + sumB
  a >= 0 && a <= sumB
end
puts ans
0