Advertisement
Kostiggig

Untitled

Mar 31st, 2023
1,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.84 KB | None | 0 0
  1. fun main() {
  2.  
  3.  
  4.     print(solve(
  5.         listOf(2, 3, 1, 3,5),
  6.         listOf(2 to 1, 1 to 1, 100 to 1, 3 to 1)
  7.     ))
  8.  
  9. }
  10.  
  11. fun solve(groups: List<Int>, rooms: List<Pair<Int, Int>>) : Boolean{
  12.     if (groups.size < rooms.size) return false
  13.  
  14.     val sortedGroups = groups.sorted()
  15.     println("groups $sortedGroups")
  16.  
  17.     val sortedRooms = rooms.sortedBy {(places, type) ->
  18.         places
  19.     }
  20.     println("rooms $sortedRooms")
  21.  
  22.  
  23.     val groupIndex = sortedGroups.size - 1
  24.     var roomIndex = sortedRooms.size - 1
  25.  
  26.     for (index in groupIndex downTo  0 ) {
  27.         if (roomIndex < 0) return false
  28.  
  29.         val countOfDancers = sortedGroups[index]
  30.         val room = rooms[roomIndex]
  31.  
  32.         val capacityRoom = room.first
  33.  
  34.         if (capacityRoom < countOfDancers) return false
  35.         roomIndex--;
  36.     }
  37.  
  38.     return true
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement