Tutte le sfide
Difficile 0 risolte 0% di accettazione

Minimum Elevator Rides

Group people into as few weight-limited elevator rides as possible.

Each person must ride exactly once. Any group can share a ride if the sum of its weights is no greater than capacity. People may be regrouped freely; their input order does not matter. Minimize the number of rides.

Implement elevator_rides(weights, capacity).

Input

weights: The weight of each person.

capacity: The maximum combined weight in a ride.

Output

Return the minimum number of rides.

Vincoli

1 ≤ people ≤ 20. 1 ≤ capacity ≤ 1,000,000,000. Every weight is between 1 and capacity.

Esempi

Esempio 1
Input:
weights = [3, 4, 5]
capacity = 7

Output atteso:
expected = 2
Input:
std::vector<long long> weights = {3, 4, 5};
long long capacity = 7;

Output atteso:
long long expected = 2;
Input:
long[] weights = new long[] {3, 4, 5};
long capacity = 7;

Output atteso:
long expected = 2;

Spiegazione

Send 3 + 4 together and 5 separately. Total weight 12 cannot fit in one ride of capacity 7.

Esempio 2
Input:
weights = [2, 2, 2]
capacity = 6

Output atteso:
expected = 1
Input:
std::vector<long long> weights = {2, 2, 2};
long long capacity = 6;

Output atteso:
long long expected = 1;
Input:
long[] weights = new long[] {2, 2, 2};
long capacity = 6;

Output atteso:
long expected = 1;

Spiegazione

All three people fit together because 2 + 2 + 2 = 6.

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.