Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. n = int(input())
  2. cash = [int(i) for i in input().split()]
  3. miss = [int(i) for i in input().split()]
  4. pr = 0
  5. maxx = 0
  6. m = 0
  7. pref = [0]
  8. summ = 0
  9. for i in range(n):
  10. summ += cash[i]
  11. pref.append(summ)
  12. for i in range(len(miss)):
  13. if i + miss[i] <= n - 1:
  14. pr = pref[i+miss[i]+1]-pref[i] #sum(cash[i:i + miss[i]])
  15. if pr > maxx:
  16. maxx = pr
  17. m = i
  18. elif pr == maxx:
  19. m = max(i, m)
  20. else:
  21. pr = pref[n]-pref[i]#sum(cash[i:])
  22. if pr > maxx:
  23. maxx = pr
  24. elif pr == maxx:
  25. m = max(i, m)
  26. pr = 0
  27. print(maxx, m)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement