#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
  int N, K;
  int *a;
  int ans = 0;
  scanf("%d%d", &N, &K);
  a = (int *)malloc(N * sizeof(int));
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
    if (a[i] > 0) ans += a[i];
  }
  int min = 10000000, min1 = 10000000, tmp = 0, tmp1 = 0;
  for (int i = 0; i < K; i++) {
    if (a[i] < 0)
      tmp1 -= a[i];
    else
      tmp += a[i];
  }
  min = tmp;
  min1 = tmp1;
  printf("%d %d\n", min, min1);
  int tmp2 = a[0];
  for (int i = K; i < N; i++) {
    if (tmp2 < 0)
      tmp1 += tmp2;
    else
      tmp -= tmp2;
    tmp2 = a[i - K + 1];
    if (a[i] < 0)
      tmp1 -= a[i];
    else
      tmp += a[i];
    if (tmp < min) min = tmp;
    if (tmp1 < min1) min1 = tmp1;
    printf("%d %d\n", min, min1);
  }
  if (min < min1)
    printf("%d\n", ans - min);
  else
    printf("%d\n", ans - min1);
  return 0;
}
