結果

問題 No.1046 Fruits Rush
ユーザー 👑 箱
提出日時 2020-05-08 21:23:03
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 1,089 bytes
コンパイル時間 17,325 ms
コンパイル使用メモリ 430,404 KB
実行使用メモリ 56,272 KB
最終ジャッジ日時 2023-09-17 01:15:52
合計ジャッジ時間 19,458 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 270 ms
52,708 KB
testcase_01 AC 263 ms
52,788 KB
testcase_02 AC 272 ms
53,000 KB
testcase_03 AC 274 ms
52,788 KB
testcase_04 AC 276 ms
52,784 KB
testcase_05 AC 272 ms
52,888 KB
testcase_06 AC 274 ms
52,848 KB
testcase_07 AC 280 ms
52,712 KB
testcase_08 AC 268 ms
52,704 KB
testcase_09 AC 273 ms
52,896 KB
testcase_10 AC 268 ms
52,784 KB
testcase_11 AC 267 ms
52,844 KB
testcase_12 AC 262 ms
52,748 KB
testcase_13 AC 262 ms
52,740 KB
testcase_14 AC 292 ms
56,216 KB
testcase_15 AC 286 ms
56,272 KB
testcase_16 AC 289 ms
56,268 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:15:24: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int
        println(a.max()!!)
                       ^
Main.kt:21:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

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

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val k = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    val b = a.filter { it >= 0 }.toMutableList()
    b.sortDescending()
    if (b.count() == 0) {
        println(a.max()!!)
    } else {
        println(b.take(minOf(k, b.count())).sum())
    }
}

fun main(args: Array<String>) {
    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