๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ฏ | ๋ฐฑ์ค€/๐Ÿ™‚ | Silver

[Kotlin, S5] ๋ฐฑ์ค€ 11116๋ฒˆ ๊ตํ†ต๋Ÿ‰

by immgga 2024. 11. 15.

์ถœ์ฒ˜: unsplash.com

 

๊ตํ†ต๋Ÿ‰(11116๋ฒˆ)

Silver 5

#๊ตฌํ˜„ #๋ธŒ๋ฃจํŠธํฌ์Šค ์•Œ๊ณ ๋ฆฌ์ฆ˜

 

๋ฌธ์ œ ๋‚ด์šฉ

 

 

๋ฌธ์ œ ์ ‘๊ทผ

๋‹ค๋ฆฌ์˜ ์™ผ์ชฝ์—์„œ ์˜ค๋Š” ์ฐจ๋“ค(๋“ค์–ด์˜ค๋Š” ์ฐจ)์˜ ์‹œ๊ฐ„๊ณผ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๋‚˜๊ฐ€๋Š” ์ฐจ๋“ค์˜ ์‹œ๊ฐ„์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ๋ฌธ์ œ์— ์–ธ๊ธ‰๋œ ๊ทœ์น™์„ ์ด์šฉํ•ด ๋‹ค๋ฆฌ๋ฅผ ์ง€๋‚œ ์ฐจ๋“ค์ด ๋ช‡ ๋Œ€์ธ์ง€ ๊ตฌํ•˜๋ฉด ๋œ๋‹ค.

 

์™ผ์ชฝ์—์„œ ์˜ค๋Š” ์ฐจ์˜ ์‹œ๊ฐ„์ด t, t + 500์ด๊ณ , ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๋‚˜๊ฐ„ ์‹œ๊ฐ„์ด t + 1000, t + 1500์ด ์žˆ๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋‹ค๋ฆฌ๋ฅผ ์ง€๋‚œ ์ฐจ๊ฐ€ ๋œ๋‹ค.

 

 

๋ฌธ์ œ ํ•ด๊ฒฐ ์ฝ”๋“œ

๋”๋ณด๊ธฐ
import java.io.BufferedReader
import java.io.InputStreamReader

fun main() {
    val bf = BufferedReader(InputStreamReader(System.`in`))
    val n = bf.readLine().toInt()

    for (i in 0 until n) {
        val m = bf.readLine().toInt()
        val left = bf.readLine().split(" ").map { it.toInt() }.toMutableList()
        val right = bf.readLine().split(" ").map { it.toInt() }.toMutableList()
        var answer = 0

        while (left.isNotEmpty()) {
            val start = left.first()
            if (left.contains(start + 500) && right.contains(start + 1000) && right.contains(start + 1500)) {
                answer++

                left.remove(start + 500)
            }

            left.removeFirst()
        }

        println(answer)
    }
}

 

๋ฌธ์ œ ํ’€์ด

t๋ฅผ start๋กœ ์žก์€ ๋‹ค์Œ์— left์— start + 500์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€, ์˜ค๋ฅธ์ชฝ์— start + 1000, start + 1500์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ์ž‘์—…์„ ์ง„ํ–‰ํ–ˆ๋‹ค.

 

 

๋ฌธ์ œ ํ•ด๊ฒฐ ๊ณผ์ •

๋ฌธ์ œ๋ฅผ ์ดํ•ดํ•˜๋Š” ๋ฐ ์‹œ๊ฐ„์ด ์ข€ ๊ฑธ๋ ธ๋‹ค.

๋ฌธ์ œ ์ดํ•ด ์ด์ „์—๋Š” ์™ผ์ชฝ -> ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๊ฐ€๋Š” ๊ฒฝ์šฐ์™€ ์˜ค๋ฅธ์ชฝ -> ์™ผ์ชฝ์œผ๋กœ ๊ฐ€๋Š” ๊ฒฝ์šฐ๋„ ํ™•์ธํ•ด์•ผ ๋˜๋Š” ๊ฒƒ์œผ๋กœ ์ฐฉ๊ฐํ–ˆ๋‹ค.

728x90