結果

問題 No.972 選び方のスコア
ユーザー simansiman
提出日時 2022-11-23 14:12:11
言語 Ruby
(3.3.0)
結果
AC  
実行時間 706 ms / 2,000 ms
コード長 516 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 11,960 KB
実行使用メモリ 34,072 KB
最終ジャッジ日時 2023-10-24 23:34:36
合計ジャッジ時間 19,460 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 696 ms
34,040 KB
testcase_01 AC 695 ms
34,016 KB
testcase_02 AC 666 ms
31,840 KB
testcase_03 AC 383 ms
25,104 KB
testcase_04 AC 701 ms
33,764 KB
testcase_05 AC 698 ms
33,760 KB
testcase_06 AC 706 ms
33,760 KB
testcase_07 AC 536 ms
29,592 KB
testcase_08 AC 677 ms
33,868 KB
testcase_09 AC 656 ms
33,356 KB
testcase_10 AC 640 ms
33,868 KB
testcase_11 AC 634 ms
33,952 KB
testcase_12 AC 641 ms
34,064 KB
testcase_13 AC 681 ms
34,064 KB
testcase_14 AC 638 ms
34,064 KB
testcase_15 AC 687 ms
34,008 KB
testcase_16 AC 686 ms
34,072 KB
testcase_17 AC 683 ms
34,072 KB
testcase_18 AC 84 ms
16,172 KB
testcase_19 AC 699 ms
33,596 KB
testcase_20 AC 699 ms
33,592 KB
testcase_21 AC 700 ms
33,592 KB
testcase_22 AC 679 ms
33,228 KB
testcase_23 AC 697 ms
33,500 KB
testcase_24 AC 698 ms
33,568 KB
testcase_25 AC 84 ms
16,172 KB
testcase_26 AC 84 ms
16,172 KB
testcase_27 AC 85 ms
16,172 KB
testcase_28 AC 85 ms
16,172 KB
testcase_29 AC 85 ms
16,172 KB
testcase_30 AC 85 ms
16,172 KB
testcase_31 AC 85 ms
16,172 KB
testcase_32 AC 84 ms
16,172 KB
testcase_33 AC 84 ms
16,172 KB
testcase_34 AC 84 ms
16,172 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 + 1

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

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

    if d2 + d1 > 0
      ok = len
    else
      ng = len
    end
  end

  len = ok
  sum1 = RUI[mid] - RUI[mid - len]
  sum2 = RUI[N] - RUI[N - len]
  sum = sum1 + sum2 - 2 * len * m

  ans = sum if ans < sum
end

puts ans
0