订单问题

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

Solution

def max_tip(N, X, Y, A, B):
    diff = []
    index = [i for i in range(N)]
    for i in range(N):
        diff.append((abs(A[i]-B[i]),index[i]))  # 求各个订单小费差,并合并序号
    diff.sort(reverse=True)  # 按小费差从大到小排序
    z = [i for x,i in diff]  # 获得排序后的订单序号
    sum = 0
    for i in z:
        if A[i] >= B[i]:
            if X > 0:  # 优先A接单
                sum += A[i]
                X -= 1
            else:
                sum += B[i]
                Y -= 1
        else:
            if Y > 0:  # 优先接单
                sum += B[i]
                Y -= 1
            else:
                sum += A[i]
                X -= 1
    return sum


if __name__ == '__main__':
    T = int(input())
    while T:
        T -= 1
        N, X, Y = map(int, input().split())
        A = list(map(int, input().split()))
        B = list(map(int, input().split()))
        print(max_tip(N, X, Y, A, B))
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 订单问题 Description Rahul and Ankit are the only two waiters...
    Vmmmg阅读 1,738评论 0 0
  • 订单问题 Description Rahul and Ankit are the only two waiters...
    loick阅读 2,361评论 0 1
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,192评论 0 10
  • “翻转”这个词,让我想到古语三翻六坐九爬爬,在婴儿约三个月时即可以翻转趴着。此时孩子的视野,从头顶一方空白开始向五...
    暖楠说成长阅读 2,299评论 1 4
  • 我拥有一座高大的钢琴,我拥有一个宽敞的书房,我还用有一个足够我玩耍的卧室。 我最欣赏我们班的陈弘宇他很聪明,我还欣...
    修炼之中阅读 1,657评论 0 1

友情链接更多精彩内容