Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun main() {
- print(solve(
- listOf(2, 3, 1, 3,5),
- listOf(2 to 1, 1 to 1, 100 to 1, 3 to 1)
- ))
- }
- fun solve(groups: List<Int>, rooms: List<Pair<Int, Int>>) : Boolean{
- if (groups.size < rooms.size) return false
- val sortedGroups = groups.sorted()
- println("groups $sortedGroups")
- val sortedRooms = rooms.sortedBy {(places, type) ->
- places
- }
- println("rooms $sortedRooms")
- val groupIndex = sortedGroups.size - 1
- var roomIndex = sortedRooms.size - 1
- for (index in groupIndex downTo 0 ) {
- if (roomIndex < 0) return false
- val countOfDancers = sortedGroups[index]
- val room = rooms[roomIndex]
- val capacityRoom = room.first
- if (capacityRoom < countOfDancers) return false
- roomIndex--;
- }
- return true
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement