結果

問題 No.972 選び方のスコア
ユーザー simansiman
提出日時 2022-11-23 13:45:42
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 545 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 11,924 KB
実行使用メモリ 34,040 KB
最終ジャッジ日時 2023-10-24 23:15:45
合計ジャッジ時間 21,314 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 691 ms
34,008 KB
testcase_01 AC 689 ms
33,984 KB
testcase_02 AC 659 ms
31,808 KB
testcase_03 AC 383 ms
25,072 KB
testcase_04 AC 688 ms
33,732 KB
testcase_05 AC 690 ms
33,728 KB
testcase_06 AC 692 ms
33,728 KB
testcase_07 AC 534 ms
29,560 KB
testcase_08 AC 664 ms
33,836 KB
testcase_09 AC 646 ms
33,324 KB
testcase_10 AC 632 ms
33,836 KB
testcase_11 AC 629 ms
33,920 KB
testcase_12 AC 666 ms
34,032 KB
testcase_13 AC 677 ms
34,032 KB
testcase_14 AC 668 ms
34,032 KB
testcase_15 AC 683 ms
33,976 KB
testcase_16 AC 680 ms
34,040 KB
testcase_17 AC 677 ms
34,036 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 87 ms
16,140 KB
testcase_26 AC 87 ms
16,140 KB
testcase_27 AC 87 ms
16,140 KB
testcase_28 AC 87 ms
16,136 KB
testcase_29 AC 87 ms
16,140 KB
testcase_30 AC 87 ms
16,140 KB
testcase_31 AC 86 ms
16,140 KB
testcase_32 AC 87 ms
16,140 KB
testcase_33 AC 89 ms
16,140 KB
testcase_34 AC 86 ms
16,140 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i).sort
RUI = [0]

A.each do |a|
  RUI << RUI.last + a
end

ans = 0

1.upto(N - 2) do |mid|
  m = A[mid]

  ok = 0
  ng = mid

  while (ok - ng).abs >= 2
    l = (ok + ng) / 2
    r = N - l - 1

    d1 = A[l] - m
    d2 = A[r] - m

    if d2 - d1 > 0
      ok = l
    else
      ng = l
    end
  end

  len = ok + 1
  sum1 = RUI[ok + 1] - len * m
  sum2 = (RUI[N] - RUI[N - ok - 1]) - len * m
  sum = sum1 + sum2
  # pp [:mid, mid, :ok, ok, :sum1, sum1, :sum2, sum2]

  ans = sum if ans < sum
end

puts ans
0