結果

問題 No.972 選び方のスコア
ユーザー yakamotoyakamoto
提出日時 2020-01-17 22:11:15
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,497 bytes
コンパイル時間 16,456 ms
コンパイル使用メモリ 427,904 KB
実行使用メモリ 78,512 KB
最終ジャッジ日時 2023-09-08 03:35:30
合計ジャッジ時間 41,802 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 924 ms
78,488 KB
testcase_01 AC 922 ms
78,412 KB
testcase_02 AC 879 ms
74,984 KB
testcase_03 AC 706 ms
64,280 KB
testcase_04 AC 877 ms
75,116 KB
testcase_05 WA -
testcase_06 AC 892 ms
74,364 KB
testcase_07 AC 838 ms
72,960 KB
testcase_08 AC 710 ms
74,056 KB
testcase_09 AC 700 ms
74,156 KB
testcase_10 AC 669 ms
74,048 KB
testcase_11 AC 670 ms
78,276 KB
testcase_12 AC 677 ms
78,188 KB
testcase_13 AC 676 ms
78,144 KB
testcase_14 AC 676 ms
78,220 KB
testcase_15 AC 750 ms
78,408 KB
testcase_16 AC 759 ms
78,400 KB
testcase_17 AC 731 ms
78,512 KB
testcase_18 AC 302 ms
57,112 KB
testcase_19 AC 943 ms
74,792 KB
testcase_20 AC 937 ms
74,580 KB
testcase_21 AC 915 ms
74,900 KB
testcase_22 WA -
testcase_23 AC 889 ms
74,848 KB
testcase_24 AC 896 ms
75,100 KB
testcase_25 AC 319 ms
57,108 KB
testcase_26 AC 312 ms
57,112 KB
testcase_27 AC 309 ms
57,068 KB
testcase_28 AC 297 ms
52,924 KB
testcase_29 AC 308 ms
53,008 KB
testcase_30 AC 335 ms
57,156 KB
testcase_31 AC 335 ms
57,032 KB
testcase_32 AC 354 ms
57,112 KB
testcase_33 AC 331 ms
57,008 KB
testcase_34 AC 322 ms
57,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007

fun main() {
  val (N) = readInts()
  val A = readLongs()

  if (N == 1 || N == 2) {
    println(0)
    return
  }

  A.sort()

  val cum = LongArray(N + 1)
  for (i in 0 until N) {
    cum[i + 1] = cum[i] + A[i]
  }

  var ans = 0L
  for (i in 0 until N) {
    var l = 0
    var h = min(i, N - 1 - i) + 1
    while(h - l > 1) {
      val m = (h + l) / 2
      if (A[N - 1 - m] + A[i - m] - A[i] * 2 >= 0) l = m
      else h = m
    }

    val v = cum[N] - cum[N - l] +
            cum[i] - cum[i - l] -
            A[i] * 2 * l

    debug{"i:$i l:$l v:$v"}
    ans = max(ans, v)
  }

  println(ans)
}












































private val isDebug = try {
  // なんか本番でエラーでる
  System.getenv("MY_DEBUG") != null
} catch (t: Throwable) {
  false
}

private fun readLn() = readLine()!!
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }.toIntArray()
private fun readLongs() = readStrings().map { it.toLong() }.toLongArray()
private inline fun debug(msg: () -> String) {
  if (isDebug) System.err.println(msg())
}
private fun debug(a: LongArray) {
  debug{a.joinToString(" ")}
}
private fun debug(a: IntArray) {
  debug{a.joinToString(" ")}
}
private fun debug(a: BooleanArray) {
  debug{a.map{if(it) 1 else 0}.joinToString("")}
}
private fun debugDim(A: Array<IntArray>) {
  if (isDebug) {
    for (a in A) {
      debug(a)
    }
  }
}
0