#K43382. Elevator Simulation

    ID: 27297 Type: Default 1000ms 256MiB

Elevator Simulation

Elevator Simulation

You are given the task of simulating an elevator system. The elevator is initially on the 1st floor and can serve a building with a given number of floors. You need to implement an elevator that processes two types of commands:

  • REQUEST x: Add a request for floor x. The request will only be added if the floor number x satisfies \(1 \leq x \leq N\) where \(N\) is the total number of floors. Duplicate requests should be ignored. If the floor is invalid, print Invalid floor request immediately.
  • MOVE: Move the elevator to the next requested floor in a first-come, first-served manner. After moving, print Current floor: X where X is the destination floor. If there are no pending requests, print No pending requests.

The commands will be provided via standard input (stdin), and your outputs should be printed to standard output (stdout) exactly in the order the commands are processed.

Note: Use the following guidelines for any invalid floor requests or duplicate requests as described in the above instructions.

inputFormat

The first line of input contains two integers: N (the total number of floors in the building) and M (the number of commands). The next M lines each contain a command. A command is either:

  • REQUEST x: where x is the floor number being requested.
  • MOVE: instructs the elevator to move.

All inputs are provided via stdin.

outputFormat

For each command processed, certain outputs are expected:

  • For a REQUEST x command: If x is not within the range [1, N], print Invalid floor request (without quotes). Otherwise, no output is generated.
  • For a MOVE command: If there is a pending floor request, the elevator moves to that floor and prints Current floor: X, where X is the floor number. If there are no pending requests, print No pending requests.

Outputs should be printed in the order the commands are processed, each on a new line, via stdout.

## sample
5 4
REQUEST 3
REQUEST 1
MOVE
MOVE
Current floor: 3

Current floor: 1

</p>