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))