結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー 👑 箱星箱星
提出日時 2020-10-09 21:40:00
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,340 bytes
コンパイル時間 13,515 ms
コンパイル使用メモリ 421,120 KB
実行使用メモリ 86,968 KB
最終ジャッジ日時 2023-09-27 15:51:29
合計ジャッジ時間 57,753 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 249 ms
52,864 KB
testcase_01 AC 270 ms
55,884 KB
testcase_02 AC 259 ms
55,932 KB
testcase_03 WA -
testcase_04 AC 256 ms
55,916 KB
testcase_05 AC 261 ms
56,028 KB
testcase_06 AC 263 ms
56,136 KB
testcase_07 WA -
testcase_08 AC 265 ms
55,792 KB
testcase_09 AC 264 ms
55,944 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 263 ms
57,832 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 262 ms
58,204 KB
testcase_17 AC 272 ms
56,264 KB
testcase_18 AC 1,136 ms
85,112 KB
testcase_19 AC 1,077 ms
83,612 KB
testcase_20 AC 723 ms
71,844 KB
testcase_21 AC 451 ms
58,660 KB
testcase_22 WA -
testcase_23 AC 431 ms
58,540 KB
testcase_24 WA -
testcase_25 AC 784 ms
71,848 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1,364 ms
85,284 KB
testcase_29 AC 1,256 ms
85,312 KB
testcase_30 WA -
testcase_31 AC 1,300 ms
86,880 KB
testcase_32 WA -
testcase_33 AC 1,161 ms
86,316 KB
testcase_34 AC 1,169 ms
86,360 KB
testcase_35 AC 1,149 ms
85,244 KB
testcase_36 WA -
testcase_37 AC 1,146 ms
85,448 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 1,226 ms
84,928 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 256 ms
56,180 KB
testcase_44 AC 264 ms
56,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextLong() }
    val b = Array(n) { sc.nextLong() }
    val map = mutableMapOf<Long, Long>()
    for (i in 0 until n) {
        map[a[i]] = (map[a[i]] ?: 0) + b[i]
    }
    val sum = map.values.sum()
    var lsum = 0L
    var rsum = sum
    for (x in map.keys.sorted()) {
        rsum -= map[x]!!
        if (lsum >= rsum) {
            var ans = 0L
            for ((k, v) in map) {
                ans += v * Math.abs(x - k)
            }
            println("$x $ans")
            return
        }
        lsum += map[x]!!
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}
0