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
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter