Egor_1425

Untitled

Jul 13th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. n, x = map(int, input().split())
  2.  
  3. a = list(map(int, input().split()))
  4. b = list(map(int, input().split()))
  5.  
  6. d = [(n-1, b[n-1])] * n
  7. mxi = n-1
  8. mx = b[n-1]
  9. for i in range(n-2, -1, -1):
  10.     if b[i] > mx:
  11.         mxi = i
  12.         mx = b[i]
  13.     d[i] = (mxi, mx)
  14.  
  15. top = x
  16. top_buy = -1
  17. top_sell = -1
  18. m = 0
  19.  
  20. for i in range(n):
  21.     h = x // a[i]
  22.     o = x % a[i]
  23.     if top_sell < i + 1:
  24.         top_sell_new = d[i][0] + 1
  25.  
  26.     m = d[i][1]
  27.     if m * h + o > top:
  28.         top = m * h + o
  29.         top_buy = i + 1
  30.         top_sell = top_sell_new
  31. print(top)
  32. print(top_buy, top_sell)
Add Comment
Please, Sign In to add comment