diff --git a/storage/zeta/kt/completed/1092.kt b/storage/zeta/kt/completed/1092.kt new file mode 100644 index 0000000..d753585 --- /dev/null +++ b/storage/zeta/kt/completed/1092.kt @@ -0,0 +1,64 @@ +fun > List.lowerBound(value: T): Int { + var left = 0 + var right = this.size + + while (left < right) { + val mid = (left + right) / 2 + if (this[mid] < value) { + left = mid + 1 + } else { + right = mid + } + } + return left +} + +fun minimumPortTime(weightLimits: List /* sorted */, weights: List): Int? { + + val weightsCntCategorized = IntArray(weightLimits.size + 1) + + + weights.forEach { + val cat = weightLimits.lowerBound(it) + weightsCntCategorized[cat]++ + } + + if (weightsCntCategorized.last() > 0) { + return null + } + + var time = 0 + while (true) { + repeat(weightLimits.size) { + for (i in (0..it).reversed()) { + if (weightsCntCategorized[i] == 0) { + continue + } else { + weightsCntCategorized[i]-- + break + } + } + } + + time++ + if (weightsCntCategorized.all { it == 0 }) { + break + } + } + + + return time +} + +fun main() = with(System.`in`.bufferedReader()) { + this.readLine() + + val weightLimits = this.readLine().split(' ').map { it.toInt() }.sorted() + this.readLine() + + val weights = this.readLine().split(' ').map { it.toInt() } + + println( + minimumPortTime(weightLimits, weights) ?: -1 + ) +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/23029.kt b/storage/zeta/kt/completed/23029.kt new file mode 100644 index 0000000..6fdd502 --- /dev/null +++ b/storage/zeta/kt/completed/23029.kt @@ -0,0 +1,36 @@ +fun maxFoodEaten(cntsFoods: List): Int { + val dp = Array(cntsFoods.size) { Array(3) { 0 } } + + // 0: 안먹을경우 + // 1: 첫번째인경우 + // 2: 두번째인경우 + + for ((i, food) in cntsFoods.withIndex()) { + if (i == 0) { + dp[i][1] = food + dp[i][2] = 0 + dp[i][0] = 0 + } else if (i == 1) { + dp[i][2] = dp[i - 1][1] + food / 2 + dp[i][1] = dp[i - 1][0] + food + dp[i][0] = dp[i - 1].max() + } else { + dp[i][0] = dp[i - 1].max() + dp[i][1] = dp[i - 1][0] + food + dp[i][2] = dp[i - 1][1] + food / 2 + } + + } + + return dp.last().max() +} + +fun main() = with(System.`in`.bufferedReader()) { + val n = this.readLine().toInt() + val cntsFoods = (1..n).map { + this.readLine().toInt() + + } + + println(maxFoodEaten(cntsFoods)) +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/26587.kt b/storage/zeta/kt/completed/26587.kt new file mode 100644 index 0000000..1473bad --- /dev/null +++ b/storage/zeta/kt/completed/26587.kt @@ -0,0 +1,11 @@ +fun main() = with(System.`in`.bufferedReader()) { + this.readLines().map { + val words = it.split(' ').toMutableList() + val vowelStarts = + words.withIndex().filter { it.value.first().lowercaseChar() in listOf('a', 'e', 'i', 'o', 'u') } + (vowelStarts zip vowelStarts.reversed()).forEach { (a, b) -> + words[a.index] = b.value + } + words.joinToString(" ") + }.forEach(::println) +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/30553.kt b/storage/zeta/kt/completed/30553.kt new file mode 100644 index 0000000..66d6e43 --- /dev/null +++ b/storage/zeta/kt/completed/30553.kt @@ -0,0 +1,47 @@ +fun main() = with(System.`in`.bufferedReader()) { + val (n, m, q) = this.readLine()!!.split(' ').map { it.toInt() } + + val characters = (1..n).map { IntArray(m) } + + repeat(n) { + val trait = this.readLine()!! + + for (i in 0 until m) { + characters[it][i] = when (trait[i]) { + 'Y' -> 2 + 'N' -> 1 + else -> 0 + } + } + } + + val queries = IntArray(m) + + repeat(q) { + val iter = this.readLine()!!.split(' ').iterator() + val index = iter.next().toInt() - 1 + queries[index] = when (iter.next().first()) { + 'Y' -> 2 + 'N' -> 1 + else -> 0 + } + } + + val filtered = characters.withIndex().filter { (ind, it) -> + (it zip queries).map { + if (it.second == 0) { + true + } else { + it.first == it.second + } + }.all { it } + } + + if (filtered.size == 1) { + println("unique") + println(filtered.first().index + 1) + } else { + println("ambiguous") + println(filtered.size) + } +} \ No newline at end of file