Advertisement
lp-gamboa

Problem D

Mar 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. # Problem D
  2. n = int(input())
  3. inp = input().split(" ")
  4. people = [ int(x) for x in inp ]
  5. inp = input().split(" ")
  6. s, f = int(inp[0]), int(inp[1])
  7. r = f-s#+1 # tamaño de la ventana
  8. max_s, idx_max = sum( people[i] for i in range(r) ), 0
  9. sum_ac = max_s
  10. res = (n-idx_max+s)%n if (n-idx_max+s)%n else n
  11. for j in range(n):
  12.     # print(sum_ac, idx_max, res)
  13.     sum_ac = sum_ac - people[j] + people[(r+j)%n]
  14.     if sum_ac>max_s:
  15.         max_s, idx_max = sum_ac, (j+1)%n
  16.         res = (n-(j+1)+s)%n if (n-(j+1)+s)%n else n
  17.     elif sum_ac==max_s:
  18.         res_1 = (n-(j+1)+s)%n if (n-(j+1)+s)%n else n
  19.         if res_1<res:
  20.             res=res_1
  21. # res = (n-idx_max+s)%n if (n-idx_max+s)%n else n
  22. print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement