Problema
Ver traducciónEach 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.
Restricciones
1 ≤ people ≤ 20. 1 ≤ capacity ≤ 1,000,000,000. Every weight is between 1 and capacity.
Ejemplos
Entrada:
weights = [3, 4, 5]
capacity = 7
Salida esperada:
expected = 2
Entrada:
std::vector<long long> weights = {3, 4, 5};
long long capacity = 7;
Salida esperada:
long long expected = 2;
Entrada:
long[] weights = new long[] {3, 4, 5};
long capacity = 7;
Salida esperada:
long expected = 2;
Explicación
Send 3 + 4 together and 5 separately. Total weight 12 cannot fit in one ride of capacity 7.
Entrada:
weights = [2, 2, 2]
capacity = 6
Salida esperada:
expected = 1
Entrada:
std::vector<long long> weights = {2, 2, 2};
long long capacity = 6;
Salida esperada:
long long expected = 1;
Entrada:
long[] weights = new long[] {2, 2, 2};
long capacity = 6;
Salida esperada:
long expected = 1;
Explicación
All three people fit together because 2 + 2 + 2 = 6.
Referencias
Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.