Python Code

PHOTO EMBED

Sat Jul 17 2021 13:39:37 GMT+0000 (Coordinated Universal Time)

Saved by @pro0616 #python

class Solution:
    def maxTip(self, a, b, n, x, y):
        c,su=[],0
        x1,y1=0,0
        for i in range(n):
            c.append(abs(a[i]-b[i]))
        d=sorted(list(enumerate(c)),key=lambda x:x[1])
        for i in d[::-1]:
            if a[i[0]]>b[i[0]] and x1<x:
                su+=a[i[0]]
                x1+=1
            elif a[i[0]]<b[i[0]] and y1<y:
                su+=b[i[0]]
                y1+=1
            elif a[i[0]]>b[i[0]] and x1==x:
                su+=b[i[0]]
                y1+=1
            elif a[i[0]]<b[i[0]] and y1==y:
                su+=a[i[0]]
                x1+=1
            elif a[i[0]]==b[i[0]]:
                su+=a[i[0]]
        return su
            
       

if __name__ == '__main__':
    tc = int(input())
    while tc > 0:
        n, x, y = list(map(int, input().strip().split()))
        a = list(map(int, input().strip().split()))
        b = list(map(int, input().strip().split()))
        ans = Solution().maxTip(a, b, n, x, y)
        print(ans)
        tc -= 1
content_copyCOPY