mfgnik

Untitled

Dec 1st, 2020 (edited)
504
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n, m = map(int, input().split())
  2. arr = list(map(int, input().split()))
  3.  
  4. for i in range(1, n):
  5.     if arr[i]:
  6.         if i - m > 0:
  7.             arr[i] = 2*arr[i-1] - arr[i-m-1]
  8.         else:
  9.             arr[i] -= 1
  10.             for jump in range(1, m + 1):
  11.                 if i - jump >= 0:
  12.                     arr[i] += arr[i - jump]
  13.     else:
  14.         arr[i] = arr[i-1]
  15.     arr[i] %= 1000000007
  16.  
  17. print(arr.pop())
  18.  
RAW Paste Data