Advertisement
mfgnik

Untitled

Dec 19th, 2020
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. n, m = map(int, input().split())
  2. positions = list(map(int, input().split()))
  3. current_sum = 0
  4. modulo = 1000000007
  5. for index in range(1, m + 1):
  6.     current_sum += positions[index - 1]
  7.     current_sum %= modulo
  8.     if positions[index]:
  9.         positions[index] = current_sum
  10. for index in range(m + 1, n):
  11.     current_sum -= positions[index - m - 1]
  12.     current_sum += positions[index - 1]
  13.     current_sum %= modulo
  14.     if positions[index]:
  15.         positions[index] = current_sum
  16. print(positions[-1])
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement