daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Jan 13th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def max_tip(N, A, B, X, Y, n= 0):
  2.  
  3.     if n == len(A) or N == 0:
  4.         return 0
  5.  
  6.     if X == 0 and Y > 0: # rahul cannot take more orders
  7.         return max(B[n] + max_tip(N - 1, A, B, X, Y - 1, n + 1), # ankit takes the order
  8.                     max_tip(N, A, B, X, Y, n + 1))  # ankit does not take order
  9.     elif Y == 0 and X > 0: # ankit cannot take more orders
  10.         return max(A[n] + max_tip(N - 1, A, B, X - 1, Y, n + 1), # rahul takes the order
  11.                     max_tip(N, A, B, X, Y, n + 1)) # rahul does not take order
  12.     elif Y == 0 and X == 0: # neither can take orders
  13.         return 0
  14.     else:
  15.         return max(A[n] + max_tip(N - 1, A, B, X - 1, Y, n + 1), # rahul takes the order
  16.                 B[n] + max_tip(N - 1, A, B, X, Y - 1, n + 1), #ankit takes the order
  17.                 max_tip(N, A, B, X, Y, n + 1)) # nobody takes the order
  18.  
  19. T = int(input())
  20.  
  21. for i in range(T):
  22.     nxy = [int(n) for n in input().strip().split(" ")]
  23.     N = nxy[0]
  24.     X = nxy[1]
  25.     Y = nxy[2]
  26.  
  27.     A = [int(n) for n in input().strip().split(" ")]
  28.     B = [int(n) for n in input().strip().split(" ")]
  29.  
  30.     print(max_tip(N, A, B, X, Y))
  31.    
  32. Input:
  33. 7 3 3
  34. 8 7 15 19 16 16 18
  35. 1 7 15 11 12 31 9
  36.  
  37. Its Correct output is:
  38. 110
  39.  
  40. And Your Code's Output is:
  41. 106
RAW Paste Data
Top