订单问题

Description
Rahul and Ankit are the only two waiters in Royal Restaurant. Today, the restaurant received N orders. The amount of tips may differ when handled by different waiters, if Rahul takes the ith order, he would be tipped Ai rupees and if Ankit takes this order, the tip would be Bi rupees.In order to maximize the total tip value they decided to distribute the order among themselves. One order will be handled by one person only. Also, due to time constraints Rahul cannot take more than X orders and Ankit cannot take more than Y orders. It is guaranteed that X + Y is greater than or equal to N, which means that all the orders can be handled by either Rahul or Ankit. Find out the maximum possible amount of total tip money after processing all the orders.

Input
• The first line contains one integer, number of test cases.

• The second line contains three integers N, X, Y.

• The third line contains N integers. The ith integer represents Ai.

• The fourth line contains N integers. The ith integer represents Bi.

Output
Print a single integer representing the maximum tip money they would receive.

Sample Input 1
1
5 3 3
1 2 3 4 5
5 4 3 2 1

Sample Output 1
21

def solution(l1, l2, o, o1, o2):
    init = [[0] * (o + 1) for i in range(o + 1)]
    for i in range(1, o + 1):
        init[0][i] = init[0][i - 1] + l2[i - 1]
        init[i][0] = init[i - 1][0] + l1[i - 1]
    for m in range(1, o + 1):
        for n in range(1, o + 1):
            if m + n <= o:
                init[m][n] = max(init[m][n - 1] + l2[m + n - 1], init[m - 1][n] + l1[m + n - 1])
            else:
                init[m][n] = max(init[m - 1][n], init[m][n - 1])
    return init[-1][-1]


if __name__ == '__main__':
    for _ in range(int(input())):
        o, o1, o2 = map(int, input().strip().split())
        l1 = list(map(int, input().strip().split()))
        l2 = list(map(int, input().strip().split()))
        result = solution(l1, l2, o, o1, o2)
        print(result)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值