#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e5 + 100, M = 1e14 + 10;   long long int n, k, l, r, mid, x, y, f[N], p[N], a[N];   vector<long long int> v;   void add(long long int v, long long int c) {     if (v == 0) return;     for (; v < N; v += v & -v) f[v] += c;   }   long long int get(long long int ind) {     long long int ret = 0;     for (; ind; ind -= ind & -ind) ret += f[ind];     return ret;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> k;     p[0] = M;     v.push_back(p[0]);     for (int i = 1; i <= n; i++) {       cin >> a[i];       p[i] = p[i - 1] + a[i];       v.push_back(p[i]);     }     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());     l = -M;     r = M;     while (r - l > 1) {       mid = l + r >> 1;       y = 0;       fill(f, f + N, 0);       for (int i = n; i >= 0; i--) {         x = upper_bound(v.begin(), v.end(), p[i] + mid - 1) - v.begin();         y += get(N - 1) - get(x + 1);         x = upper_bound(v.begin(), v.end(), p[i]) - v.begin();         add(x + 1, 1);       }       if (y >= k)         l = mid;       else         r = mid;     }     cout << l << endl;   }   