← 返回 airbnb 的题目列表Booking System: Choose Properties to Fit a Group with Minimal Waste
类型:online_judge
Problem: Booking System (Choose Properties to Fit a Group)
You are given a list of properties. Each property has:
id: unique identifier
neighborhood: the neighborhood it belongs to
capacity: a positive integer capacity
You are also given:
targetNeighborhood
groupSize (positive integer)
Choose a subset of properties within targetNeighborhood such that the sum of capacities is at least groupSize.
Among all feasible subsets, pick the optimal one using this priority order:
Minimize total capacity sum(capacity) (minimize wasted capacity).
If tied, minimize the number of properties selected.
Output the list of selected property ids (any order).
Edge cases
Capacities are positive integers.
There may be duplicated capacities.
If no feasible subset exists in the target neighborhood, return an empty list (or equivalent).
Example
If targetNeighborhood="N1", groupSize=7, and properties are:
(id=1, N1, cap=2)
(id=2, N1, cap=3)
(id=3, N1, cap=4)
(id=4, N2, cap=10)
The optimal solution is {2,3} with total capacity 7.
Sample tests (5)
(See the Chinese section for concrete cases.)
Example
Input
N1
7
3
1 N1 2
2 N1 3
3 N1 4
Output
2 3