結果

問題 No.1715 Dinner 2
ユーザー 箱星
提出日時 2021-10-22 21:45:59
言語 Kotlin
(2.1.0)
結果
WA  
実行時間 -
コード長 1,487 bytes
コンパイル時間 13,499 ms
コンパイル使用メモリ 455,360 KB
実行使用メモリ 92,108 KB
最終ジャッジ日時 2024-09-23 05:10:10
合計ジャッジ時間 39,357 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26 WA * 1 TLE * 5 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextInt()
    val d = nextInt()
    val (p, q) = Array(n) { nextInt() to nextInt() }.unzip().toList().map { it.toTypedArray() }
    var ans = Long.MIN_VALUE
    for (i in 0 until n) {
        for (j in 0 until n) {
            if (i == j) continue
            var now = 0L
            var min = 0L
            for (k in 0 until d) {
                if (k and 1 == 0) {
                    now -= p[i]
                    min = minOf(min, now)
                    now += q[i]
                } else {
                    now -= p[j]
                    min = minOf(min, now)
                    now += q[j]
                }
            }
            ans = maxOf(ans, min)
        }
    }
    println(ans)
}

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", abs(1L.shl(26)))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

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()
// endregion
0