Economical Trip
Problem statement
A company has n teams. The integer array teamSizes gives the number of members in each team, and carSeats[i] gives the number of seats in the one car owned by team i.
A team participates in the company trip only when it has more than two members. If a team does not participate, neither its members nor its car are used. Members of participating teams may share cars across team boundaries.
Return the minimum number of participating teams' cars needed to carry every participating member. Return -1 if no team participates or if the available participating cars cannot carry everyone.
Function
minimumCars(n: int, teamSizes: int[], carSeats: int[]) → intExamples
Example 1
n = 3teamSizes = [4,5,7]carSeats = [7,6,7]return = 3All three teams participate, so 16 members need seats. The two largest cars have only 14 seats together, so all three cars are required.
Example 2
n = 4teamSizes = [4,2,3,5]carSeats = [6,9,5,7]return = 2The second team does not participate, so its 9-seat car is unavailable. The remaining teams have 12 members, and the 7- and 6-seat cars can carry them using two cars.
Example 3
n = 3teamSizes = [2,1,2]carSeats = [5,4,6]return = -1No team has more than two members, so nobody participates and the required result is -1.
Constraints
1 <= n <= 10^5.teamSizes.length == n.carSeats.length == n.1 <= teamSizes[i] <= 10^9.1 <= carSeats[i] <= 10^9.