#include <bits/stdc++.h>
using namespace std;
const int N = 200043;
const int MOD = 998244353;
int fact[N];
long long Binexpo(long long a, long long b) {
  if (b == 0) return 1;
  long long res = Binexpo(a, b / 2);
  if (b % 2) {
    return res * res * a;
  } else {
    return res * res;
  }
}
int add(int x, int y) {
  x += y;
  while (x >= MOD) x -= MOD;
  while (x < 0) x += MOD;
  return x;
}
int mul(int x, int y) { return (x * 1ll * y) % MOD; }
int inv(int x) { return Binexpo(x, MOD - 2); }
int divide(int x, int y) { return mul(x, inv(y)); }
void precalc() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) fact[i] = mul(fact[i - 1], i);
}
int C(int n, int k) { return divide(fact[n], mul(fact[k], fact[n - k])); }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long primechk[10000];
void preprocess(long long N) {
  long long i, j;
  for (i = 2; i <= N; i++) {
    primechk[i] = 1;
  }
  for (i = 2; i <= N; i++) {
    if (primechk[i] == 1) {
      for (j = 2; i * j <= N; j++) {
        primechk[i * j] = 0;
      }
    }
  }
}
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long Pwr(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b % 2) {
      res = res * a % m;
    }
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
int main() {
  long long a, b, c, d, e, f, g = 500, h, i, j, k, x, y, z, sum = 0, cnt = 0, n,
                              l, r, hi, lo, testc, val = 1;
  testc = 1;
  long long mx = 0;
  while (testc--) {
    cin >> n >> k;
    int arr[n];
    for (i = 0; i < n; i++) {
      cin >> arr[i];
    }
    sort(arr, arr + n);
    for (i = 0; i < k; i++) {
      sum += arr[i];
      mx = max(mx, sum);
    }
    for (i = k; i < n; i++) {
      sum -= arr[i - k];
      sum += arr[i];
      mx = max(mx, sum);
    }
    cout << mx;
  }
  return 0;
}
