#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include "ext/pb_ds/hash_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/trie_policy.hpp"
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
using ll = long long;
const ll inf = 1e15;

struct solve{
    void run(){
        int n, k;
        cin >> n >> k;
        vector<pair<int, int>> nums(n);
        vector<int> init_nums(n);
        for(int i = 0; i < n; ++i){
            cin >> nums[i].first;
            nums[i].second = i;
            init_nums[i] = nums[i].first;
        }
        sort(nums.begin(), nums.end(), greater<pair<int, int>>());

        ll res = 0;
        int last_ind = 0;
        for(int i = 0; i < k-1; ++i){
            res += nums[i].first;
            last_ind = max(last_ind, nums[i].second);
        }
        if(last_ind == n-1){
            res += nums[k-1].first;
            res += n;
        }
        else{
            res += last_ind + 1;
            int max_adder = 0;
            int iter = 1;
            for(int i = last_ind + 1; i < n; ++i){
                if(init_nums[i] + iter > max_adder){
                    max_adder = init_nums[i] + iter;

                }
                ++iter;
            }
            res += max_adder;
        }
        cout << res << endl;

    }
};

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(0);
    int t = 1;
#ifdef LOCAL
    freopen("main.in", "r", stdin);
    freopen("main.out", "w", stdout);
    cin >> t;
#endif


    while (t--){
        solve().run();
    }

    return 0;
}
