Simulate a single elevator using the SCAN algorithm: serve all requests in the current direction before reversing.
Simulate one elevator in a building with floors 1..N. The elevator starts at floor 1, IDLE. It uses the SCAN ("elevator") algorithm: while moving in a direction it stops at every requested floor in that direction; when no requests remain ahead, it reverses if requests exist behind, otherwise goes idle.
Each STEP advances the simulation by one action.
Commands:
- INIT <N> : first line; number of floors.
- REQUEST <floor> : register a stop request at <floor>.
- STEP : advance one action and print exactly one event:
- "OPEN <floor>" if the elevator opens its doors at a requested floor this step,
- "MOVE <floor>" showing the new current floor after moving one floor,
- "IDLE <floor>" if there is nothing to do.
If the current floor is a requested floor at the moment of a STEP, that STEP opens there.
- STATE : print "<floor> <direction>", direction in {UP, DOWN, IDLE}.
Direction selection from IDLE: choose the direction toward the nearest requested floor; on a tie, choose UP. Once moving, keep serving in that direction until no requests remain ahead of the elevator.