Lift Management System
Time Limit: 10s
Memory Limit: 256MB

Our lovely building, Wisma GEBEKAHI, is equipped with a series of elevators. Your challenge is to optimize the use of these resources by designing a highly efficient elevator system. The primary objective is to minimize the score.

Update on main.cpp code:

  1. Security Patch: Users no longer can call function get_next_second(), move_lift(), or enter_lift() from inside function number_of_lift_to_be_activated() or new_request().
  2. Balance Changes:
  • waiting_time score calculation is changed from waiting_time * waiting_time to waiting_time * (waiting_time + 1) / 2.
  • MAX_LIFT from 10 to 16.
  • LIFT_ACTIVATION_COST from 100.000 to 20.000.

Code Explanation

(This explanation is a spoiler. You can still understand the code without reading this explanation):

1. Function number_of_lift_to_be_activated()

  • Every test case starts with function number_of_lift_to_be_activated() that will be called once by main.cpp.
  • This function's parameter will provide basic information for the current test case.
  • Return value between 1 to 16, representing the number of lifts used to complete the request for the current test case.
  • Every lift will cost 20.000 score point to activate.

2. Function start_day()

  • After function number_of_lift_to_be_activated(), function start_day() will be called once by main.cpp.
  • The day starts at time 0 second.
  • All lifts start at floor 1.
  • At this point of time, it is guaranteed there is no request to do.
  • Users are expected to finish the function start_day() only when all the requests on this test case are completed (reached their target floor).

3. Function get_next_second()

  • Users are required to call function get_next_second() to increase the time by 1 second.

4. Function new_request()

  • Inside the function get_next_second(), function new_request() will be called.
  • This function will provide all new requests information at that current second.
  • It is guaranteed that the last request will be given at most at time 50.000 seconds.
  • If users call function get_next_second() at time greater than 50.000 seconds, then users will not get any new_request(), since all the requests for that test case has been given to the users.

5. Function move_lift()

  • This function is used to control the movement of the lift.
  • If this function is called when the lift is empty (no passenger), it will move to the target floor.
  • If this function is called when the lift is not empty, this function call will be ignored, and users will be costed 1000 score points.
  • To conclude, use this function only when the lift is empty.

6. Function enter_lift()

  • This function is used to assign passenger (request) to a lift.
  • Following are the condition for the function call:
    • The lift current floor position is the same with the passenger's request start floor:
      • Lift is empty, the passenger will enter the lift, and the lift will move towards the passenger's requested target floor.
      • Lift is not empty and moving towards same general direction with the passenger's requested target floor, the passenger will enter the lift.
    • The lift has maximum capacity of 15 passengers.
    • If the above condition is not met, this function call will be ignored, and users will be costed 1000 score points.

7. Lift movement

  • If there is passenger inside the lift, the lift will move automatically to the passenger's requested target floor. Because of this, the lift can only move on one direction (either only go up or only go down) to transport all of the current passengers inside the lift to their requested target floor.
  • Notice that when assigning passenger to the lift or calling function move_lift(), the lifts will not magically appear at their target floor, to make the lift move, user are required to call function get_next_second(), by calling this function besides from increasing time 1 second and getting new request information, the lift will also move 1 floor or not move (when there is no passenger inside the lift or no move_lift() command currently given to this lift).
  • After the lift move, if there are passengers inside the lift that has reached their requested floor, they will immediately leave the lift, and this request will be counted as completed.

8. Score calculation

  • Cost of the lift activation.
  • Every time 1 lift moves 1 floor, it will cost 10 score point.
  • Cost of waiting time for each request: If it's too long to assign request to the lift, it will also cost user some score point based on how long the waiting time for each request, the waiting time score calculation can be found on the main.cpp code.
  • Cost of invalid function call.