結果

問題 No.972 選び方のスコア
ユーザー yakamotoyakamoto
提出日時 2020-01-17 22:19:41
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 949 ms / 2,000 ms
コード長 1,493 bytes
コンパイル時間 19,624 ms
コンパイル使用メモリ 428,268 KB
実行使用メモリ 79,236 KB
最終ジャッジ日時 2023-09-08 03:59:37
合計ジャッジ時間 42,623 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 935 ms
78,612 KB
testcase_01 AC 940 ms
79,236 KB
testcase_02 AC 895 ms
74,932 KB
testcase_03 AC 728 ms
64,248 KB
testcase_04 AC 930 ms
74,540 KB
testcase_05 AC 920 ms
74,432 KB
testcase_06 AC 930 ms
74,976 KB
testcase_07 AC 857 ms
73,396 KB
testcase_08 AC 693 ms
74,108 KB
testcase_09 AC 700 ms
74,128 KB
testcase_10 AC 678 ms
74,048 KB
testcase_11 AC 685 ms
78,276 KB
testcase_12 AC 686 ms
78,156 KB
testcase_13 AC 695 ms
78,544 KB
testcase_14 AC 706 ms
78,260 KB
testcase_15 AC 776 ms
78,660 KB
testcase_16 AC 756 ms
78,392 KB
testcase_17 AC 764 ms
78,512 KB
testcase_18 AC 315 ms
57,012 KB
testcase_19 AC 929 ms
75,036 KB
testcase_20 AC 929 ms
76,268 KB
testcase_21 AC 920 ms
75,136 KB
testcase_22 AC 949 ms
74,868 KB
testcase_23 AC 935 ms
74,224 KB
testcase_24 AC 920 ms
75,164 KB
testcase_25 AC 319 ms
57,132 KB
testcase_26 AC 319 ms
57,140 KB
testcase_27 AC 319 ms
56,992 KB
testcase_28 AC 302 ms
53,412 KB
testcase_29 AC 304 ms
52,996 KB
testcase_30 AC 323 ms
57,136 KB
testcase_31 AC 322 ms
57,036 KB
testcase_32 AC 321 ms
57,088 KB
testcase_33 AC 334 ms
57,472 KB
testcase_34 AC 334 ms
57,368 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 - 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