TopcoderArchive
Archive
Algorithm problem

ElevatorScheduling

Problem statement, definition, constraints, and public examples.

Problem Statement

A tall building has only one elevator. At the end of the day, there are many people who want to get to the parking garage (in the basement, one floor below the 0-th floor). You are given a int[] floor, the i-th element of which represents the number of people waiting for the elevator on the i-th floor. The elevator is initially on the basement (one floor below the 0-th), and it can move at a speed of 1 floor per second. All other actions (like picking up passengers, switching directions, dropping off passengers, etc.) are instantaneous. A maximum of capacity people can fit into the elevator simultaneously. Return the maximum possible number of people that can reach the basement in timeLimit seconds.

Definition

Class:
ElevatorScheduling
Method:
maxNumberOfPeople
Parameters:
int, int, int[]
Returns:
int
Method signature:
int maxNumberOfPeople(int capacity, int timeLimit, int[] floor)
(be sure your method is public)

Constraints

  • capacity will be between 1 and 3000, inclusive.
  • timeLimit will be between 1 and 3000, inclusive.
  • floor will contain between 1 and 50 elements, inclusive.
  • Each element of floor will be between 0 and 3000, inclusive.
  • The sum of all elements of floor will be between 1 and 3000, inclusive.

Examples

  1. 1
    10
    {1000}
    Returns: 5
    The elevator can go up (to the 0-th floor) and get back no more than 5 times.
  2. 1
    10
    {1,1,1,1,1,1,1,1,1,1}
    Returns: 2
    The elevator can transport a person from floor 0 and a person from floor 1.
  3. 1000
    1
    {1}
    Returns: 0
  4. 10
    10
    {1,10,10,20}
    Returns: 20
  5. 5
    8
    {0,10}
    Returns: 10
Back to all problems