Post

Booking Room

Going to a contest such NWERC is not all fun and games, there are also some wordly matters to tend to. One of these is to book hotel rooms in time, before rooms in town are booked.

In this problem, you should write a program to search for available room in a given hotel. The hotel has r rooms, numbered from 1 to r, and you will be given a list describing which of these rooms already booked.

The input consist of :

One line with two integers, r and n (1≤𝑟≤100, 0≤𝑛≤𝑟), the number of rooms in the hotel and the numbers of rooms that already booked, respectively.

n lines, each which an integer between 1 and r (inclusive), a room number that is already booked.

All n room numbers of the already booked rooms are distinct.

Voila, here is the code in c++.

 

#include <bits/stdc++.h>
using namespace std;

int main(){
 

int n_rooms, n_rooms_booked;
cin >> n_rooms >> n_rooms_booked;
unordered_set<int> rooms ({n_rooms});
while(--n_rooms){
rooms.insert(n_rooms);
}
int room;
while(n_rooms_booked--){
cin >> room;
rooms.erase(room);
}
if(rooms.size()){
cout << *rooms.begin();
} else {
cout << "too late";
}

return 0;
}