#include <bits/stdc++.h>

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<pair<int, int>>;
using vc = vector<char>;
using vb = vector<bool>;
template<typename T>
using ve = vector<T>;
template<typename T1, typename T2>
using pr = pair<T1, T2>;

const int INF = 1e9 + 1;
const long long INFLL = 1e18 + 1;
const int MOD = 1e9 + 7;

inline void fchmin(int &a, int &b) { a = min(a, b); }
inline void fchmax(int &a, int &b) { a = max(a, b); }

template<typename T>
inline bool chmin(T &a, T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
inline bool chmax(T &a, T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

// #include<ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

int reps = 1;


struct SegTree {
    struct Node {
        int cnt; ll summ;

        Node() : cnt(0), summ(0) {}
        Node(int a, ll b) : cnt(a), summ(b) {}
    };

    Node merge(const Node &l, const Node &r) {
        return Node(l.cnt + r.cnt, l.summ + r.summ);
    }

    int maxn;
    ve<Node> st;

    SegTree() {}
    SegTree(int n) : maxn(n) {
        st.resize(4 * maxn);
    }

    void update(int i, ll x, int v, int l, int r) {
        if (r - l == 1) {
            if (x < 0) st[v].cnt--;
            else st[v].cnt++;
            st[v].summ += x;
            return;
        }
        int mid = (r + l) / 2;
        if (i < mid) update(i, x, 2 * v + 1, l, mid);
        else update(i, x, 2 * v + 2, mid, r);
        st[v] = merge(st[2 * v + 1], st[2 * v + 2]);
    }

    void update(int i, ll x) { update(i, x, 0, 0, maxn); }

    Node get(int ql, int qr, int v, int l, int r) {
        if (qr <= l || r <= ql) return Node();
        if (ql <= l && r <= qr) return st[v];
        int mid = (r + l) / 2;
        return merge(get(ql, qr, 2 * v + 1, l, mid), get(ql, qr, 2 * v + 2, mid, r));
    }

    Node get(int ql, int qr) { return get(ql, qr, 0, 0, maxn); }

    ll getKmaxs(int k) {
        int l = 0, r = maxn;
        int v = 0;
        ll res = 0;
        while (k) {
            // cerr << l << ' ' << r << ' ' << k << ' ' << res << '\n';
            if (k == st[v].cnt) {
                res += st[v].summ;
                break;
            }
            int mid = (r + l) / 2;
            if (st[2 * v + 2].cnt == k) {
                res += st[2 * v + 2].summ;
                break;
            } else if (st[2 * v + 2].cnt > k) {
                l = mid;
                v = 2 * v + 2;
            } else {
                res += st[2 * v + 2].summ;
                k -= st[2 * v + 2].cnt;
                v = 2 * v + 1;
                r = mid;
            }
        }
        return res;
    }
};

using vll = vector<ll>;

int getCoord(vll &nums, ll x) {
    return lower_bound(all(nums), x) - nums.begin();
}

void solve() {
    int n, k; cin >> n >> k;
    vll a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    // vll nums = a;
    // sort(all(nums));
    // nums.resize(unique(all(nums)) - nums.begin());
    ll ans = 0;
    // int m = nums.size();
    // SegTree tree(m);
    // vi coord(n);
    // for (int i = 0; i < n; i++) {
        // coord[i] = getCoord(nums, a[i]);
        // tree.update(coord[i], a[i]);
    // }
    multiset<int, greater<int>> ost;
    vi nums;
    for (int i = 0; i < n; i++) nums.push_back(a[i]);
    sort(rall(nums));
    int kmaxSumm = 0;
    for (int i = 0; i < k - 1; i++) {
        kmaxSumm += nums[i];
    }
    for (int i = k - 1; i < n; i++) {
        ost.insert(nums[i]);
    }
    for (int i = n - 1; i >= 0; i--) {
        if (i + 1 < k) break;
        if (ost.count(a[i])) {
            ost.erase(ost.find(a[i]));
        } else {
            kmaxSumm -= a[i];
            kmaxSumm += *ost.begin();
            ost.erase(ost.begin());
        }
        // tree.update(coord[i], -a[i]);
        ll curans = i + 1 + a[i] + kmaxSumm;
        ans = max(ans, curans);
        // cout << tree.st[0].cnt << ' ' << tree.st[0].summ << '\n';
    }
    cout << ans << '\n';
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    cin >> reps;
    #endif

    for (int i = 1; i <= reps; i++) {
        #ifdef LOCAL
        cout << "===== Test #" << i << " ========\n";
        #endif
        solve();
        #ifdef LOCAL
        cout << "==== End test =====\n\n";
        #endif
    }
}