Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader
- import java.io.File
- /**
- *
- */
- private fun readLn() = readLine()!! // string line
- private fun readInt() = readLn().toInt() // single int
- private fun readStrings() = readLn().split(" ") // list of strings
- private fun readInts() = readStrings().map { it.toInt() } // list of ints
- /**
- * Can we place all doors while leaving rooms for each arriving employee available
- */
- fun main() {
- val filename = "/Users/gautamroy/code/java/kt-practice/i"
- File(filename).bufferedReader().use { it.solve() }
- // solve()
- }
- private fun BufferedReader.solve() {
- val (n, m) = readInts()
- val a = readInts()
- val q = readInt()
- for (i in 0 until q) {
- var ai = 0
- val w = readInts()
- val numEmp = w.size - 1
- val asum = a.sum() // 1
- if (asum + numEmp > m) {
- println("NO")
- continue
- }
- var lastPlaced = 0
- var space = 0
- for (j in 1 until w.size) {
- space = w[j] - lastPlaced - 1
- while (ai != a.size && space >= a[ai]) {
- space -= a[ai]
- ai++
- }
- lastPlaced = w[j]
- if (ai == a.size) break
- }
- space = m - lastPlaced
- while (ai < a.size && space >= a[ai]) {
- space -= a[ai]
- ai++
- }
- if (ai == a.size) {
- println("YES")
- } else {
- println("NO")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment