Submission #54326316


Source Code Expand

import MutableIntMap.Companion.mutableIntMapOf
import java.io.*
import java.util.*
import kotlin.collections.*
import kotlin.math.*

val INPUT: InputStream = System.`in`
val OUTPUT: PrintStream = System.out

val _reader = INPUT.bufferedReader()

var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (!_tokenizer.hasMoreTokens()) {
        _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
    }
    return _tokenizer.nextToken()
}

fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readInts(n: Int) = List(n) { readInt() }
fun readIntArray(n: Int) = IntArray(n) { readInt() }
fun readDoubles(n: Int) = List(n) { readDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }
fun readLongs(n: Int) = List(n) { readLong() }
fun readLongArray(n: Int) = LongArray(n) { readLong() }

val _writer = PrintWriter(OUTPUT, false)
inline fun output(block: PrintWriter.() -> Unit) {
    _writer.apply(block).flush()
}

class MutableIntMap<K> : LinkedHashMap<K, Int>() {
    override operator fun get(key: K): Int = super.get(key) ?: 0

    fun increment(key: K, value: Int = 1) {
        this[key] = this[key] + value
    }

    companion object {
        fun <K> mutableIntMapOf(vararg pairs: Pair<K, Int>) =
            MutableIntMap<K>().apply { putAll(pairs) }
    }
}

typealias Pii = Pair<Int, Int>
fun readPii() = readInt() to readInt()
fun readPiis(n: Int) = List(n) { readPii() }

infix fun Int.hasBit(i: Int): Boolean = this and (1 shl i) > 0
infix fun Int.xorBit(i: Int): Int = this xor (1 shl i)
infix fun Long.hasBit(i: Int): Boolean = this and (1L shl i) > 0
infix fun Long.xorBit(i: Int): Long = this xor (1L shl i)

fun largerStackSize(stackSizeMegaBytes: Int = 100, action: () -> Unit) {
    Thread(null, action, "", 1024L * 1024 * stackSizeMegaBytes).apply {
        start()
        join()
    }
}

// #################################################################################################

fun solve() {
    val n = readInt()
    var m = readInt()
    val h = readInts(n)
    for ((index, value) in h.withIndex()) {
        if (value > m) {
            println(index)
            return
        }
        m -= value
    }
    println(n)
}

fun main() {
//    repeat(readInt()) { solve() }
    solve()
}

Submission Info

Submission Time
Task A - Sanitize Hands
User wangchaohui
Language Kotlin (Kotlin/JVM 1.8.20)
Score 100
Code Size 2467 Byte
Status AC
Exec Time 49 ms
Memory 37932 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 19
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt
Case Name Status Exec Time Memory
example_00.txt AC 44 ms 37708 KiB
example_01.txt AC 44 ms 37920 KiB
example_02.txt AC 44 ms 37904 KiB
hand_00.txt AC 45 ms 37752 KiB
hand_01.txt AC 45 ms 37712 KiB
hand_02.txt AC 49 ms 37932 KiB
hand_03.txt AC 44 ms 37892 KiB
hand_04.txt AC 43 ms 37928 KiB
hand_05.txt AC 47 ms 37768 KiB
random_00.txt AC 47 ms 37792 KiB
random_01.txt AC 44 ms 37688 KiB
random_02.txt AC 49 ms 37868 KiB
random_03.txt AC 44 ms 37708 KiB
random_04.txt AC 43 ms 37592 KiB
random_05.txt AC 46 ms 37840 KiB
random_06.txt AC 47 ms 37872 KiB
random_07.txt AC 48 ms 37776 KiB
random_08.txt AC 44 ms 37924 KiB
random_09.txt AC 44 ms 37912 KiB