SHARE
TWEET

Untitled

a guest Nov 15th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n, k = map(int, input().split())
  2. a = list(map(int, input().split()))
  3. b = [0] * (n - k + 1)
  4. for i in range(k):
  5.     b[0] += (-1)**i * (i + 1) * a[i]
  6. for i in range(1, k + 1):
  7.     b[1] += (-1)**(i + 1) * i * a[i]
  8. # s = (b[0] + b[1] - a[0] - (-1)**(k + 1) * k * a[k]) * (-1)
  9. s = b[0] + b[1]
  10. print(b[0], b[1], end=' ')
  11. for i in range(2, n - k + 1):
  12.     s -= a[i - 2] + (-1)**(k + 1) * k * a[i + k - 2]
  13.     s = -s + (-1)**(k + 1) * a[i + k - 2] + (-1)**(k + 1) * a[i + k - 1]
  14.     b[i] = s - b[i - 1]
  15.     print(b[i], end=' ')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top