문제
번역본 보기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.
제약 조건
1 ≤ people ≤ 20. 1 ≤ capacity ≤ 1,000,000,000. Every weight is between 1 and capacity.
예시
입력:
weights = [3, 4, 5]
capacity = 7
예상 출력:
expected = 2
입력:
std::vector<long long> weights = {3, 4, 5};
long long capacity = 7;
예상 출력:
long long expected = 2;
입력:
long[] weights = new long[] {3, 4, 5};
long capacity = 7;
예상 출력:
long expected = 2;
설명
Send 3 + 4 together and 5 separately. Total weight 12 cannot fit in one ride of capacity 7.
입력:
weights = [2, 2, 2]
capacity = 6
예상 출력:
expected = 1
입력:
std::vector<long long> weights = {2, 2, 2};
long long capacity = 6;
예상 출력:
long long expected = 1;
입력:
long[] weights = new long[] {2, 2, 2};
long capacity = 6;
예상 출력:
long expected = 1;
설명
All three people fit together because 2 + 2 + 2 = 6.
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.