I am trying to solve this problem: There are n customers queuing at post office to wait to send parcels. a[0], a[1], ..., a[n-1] is the list of shipping costs of n customers from the 1st to the nth person. It takes exactly a minute for the postal worker to complete the information needed for a customer to send a parcel. However, all customers are too busy to wait for more than a certain period of time. t[0], t[1], ..., t[n-1] is the list of minutes each of n customers can spend at the post office. Help the postal worker to find a way to serve customers so that the post office can get the largest amount of money, knowing that the staff is allowed to refuse to serve some customers for the profitable reason.)
Example:
- For
a = [10, 20, 5, 12], t = [2, 3, 3, 1], the output should be42. Explanation: The order of the customers is: the 4th person -> the 1st person -> the 2nd person (1-based indexing) - For
a = [5, 1, 3, 2], t = [3, 1, 2, 2], the output should be10. Explanation: Although the 2nd person can wait only 1 minute, this person has to pay the smallest cost. Therefore, the postal worker will not serve this customer. The order of the customers is: the 3rd person -> the 4th person -> the 1st person.
I think it is a variant of the knapsack problem, I can solve it by using brute force but only for small input. Can someone help me to solve this problem? Thanks.