#include <bits/stdc++.h>
using namespace std;
const int MaxN = 110000;
int n, a[MaxN];
long long m, s[MaxN], Data[MaxN], Ans;
int Left[MaxN], Right[MaxN], Root, Total, Size[MaxN], Key[MaxN];
inline void LeftRotate(int &t) {
  const int k = Right[t];
  Right[t] = Left[k];
  Left[k] = t;
  Size[k] = Size[t];
  Size[t] = Size[Left[t]] + Size[Right[t]] + 1;
  t = k;
}
inline void RightRotate(int &t) {
  const int k = Left[t];
  Left[t] = Right[k];
  Right[k] = t;
  Size[k] = Size[t];
  Size[t] = Size[Left[t]] + Size[Right[t]] + 1;
  t = k;
}
int Insert(int &t, const long long k) {
  if (!t) {
    Data[t = ++Total] = k;
    Size[t] = 1;
    Left[t] = Right[t] = 0;
    return Key[t] = rand();
  }
  ++Size[t];
  if (k < Data[t]) {
    if (Insert(Left[t], k) < Key[t]) RightRotate(t);
  } else if (Insert(Right[t], k) < Key[t])
    LeftRotate(t);
  return Key[t];
}
inline int Count(int t, const long long k) {
  int Res = 0;
  while (t)
    if (Data[t] > k)
      t = Left[t];
    else {
      Res += Size[Left[t]] + 1;
      t = Right[t];
    }
  return Res;
}
bool Check(const long long k) {
  Total = Root = 0;
  long long Res = 0;
  for (int i = 1; i <= n; ++i) {
    Insert(Root, s[i - 1]);
    Res += Count(Root, s[i] - k);
  }
  return Res >= m;
}
int main() {
  Key[0] = 0x7FFFFFFF;
  srand(time(0));
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    s[i] = s[i - 1] + a[i];
    if (a[i] > 0) Ans += a[i];
  }
  for (long long l = s[n] - Ans, r = Ans, mid = l + r >> 1; l <= r;
       mid = l + r >> 1)
    Check(mid) ? l = (Ans = mid) + 1 : r = mid - 1;
  cout << Ans << endl;
  return 0;
}
