CSES — Hotels, help

Правка en1, от kmcc, 2018-09-22 15:31:11

The problem statement is as follows :

There are N hotels and M groups. For each hotel you know the number of free rooms. Your task is to assign hotel rooms for groups of tourists. All members of a group want to stay in the same hotel.

The groups will come to you one after another, and you know for each group the number of rooms it requires. You always assign a group to the first hotel that has enough rooms. After this, the number of free rooms in the hotel decreases.

1 <= N, M <= 10^5

Source

I can't come up with a better solution than a linear scan for each group. Please help.

Теги #implementation, #adhoc

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский kmcc 2018-09-22 15:31:11 668 Initial revision (published)