Guest User

Untitled

a guest
May 28th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.33 KB | None | 0 0
  1. import java.io.BufferedReader
  2. import java.io.File
  3.  
  4. /**
  5.  * Can we place all doors while leaving rooms for each arriving employee available
  6.  */
  7. fun main() {
  8.     val filename = "/Users/gautamroy/code/java/kt-practice/i"
  9.     File(filename).bufferedReader().use { it.solve() }
  10. //    solve()
  11. }
  12.  
  13. private fun BufferedReader.solve() {
  14.     val (n, m) = kotlin.io.readLine()!!.map { it.toInt() }
  15.     val a = kotlin.io.readLine()!!.map { it.toInt() }
  16.     val q = kotlin.io.readLine()!!.toInt()
  17.     for (i in 0 until q) {
  18.         var ai = 0
  19.         val w = kotlin.io.readLine()!!.map { it.toInt() }
  20.         val numEmp = w.size - 1
  21.         val asum = a.sum() // 1
  22.  
  23.         if (asum + numEmp > m) {
  24.             println("NO")
  25.             continue
  26.         }
  27.  
  28.         var lastPlaced = 0
  29.         var space = 0
  30.         for (j in 1 until w.size) {
  31.             space = w[j] - lastPlaced - 1
  32.             while (ai != a.size && space >= a[ai]) {
  33.                 space -= a[ai]
  34.                 ai++
  35.             }
  36.             lastPlaced = w[j]
  37.             if (ai == a.size) break
  38.         }
  39.         space = m - lastPlaced
  40.         while (ai < a.size && space >= a[ai]) {
  41.             space -= a[ai]
  42.             ai++
  43.  
  44.         }
  45.  
  46.         if (ai == a.size) {
  47.             println("YES")
  48.         } else {
  49.             println("NO")
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment