Problem:
Max Score: 350 Points

Problem Statement

There are N buildings along the line. The i-th building from the left is colored in color i, and its height is currently a_i meters.

Chokudai is a mayor of the city, and he loves colorful thigs. And now he wants to see at least K buildings from the left.

You can increase height of buildings, but it costs 1 yens to increase 1 meters. It means you cannot make building that height is not integer.

You cannot decrease height of buildings.

Calculate the minimum cost of satisfying Chokudai's objective.

Note: "Building i can see from the left" means there are no j exists that (height of building j) ≥ (height of building i) and j < i.

Input Format

N K
a_1 a_2 a_3 ... a_N

Output Format

Print the minimum cost in one line. In the end put a line break.

Constraints

1 ≤ K ≤ N ≤ 15

1 ≤ a_i ≤ 10^9

Scoring

Subtask 1 [120 points]

N = K

Subtask 2 [90 points]

N ≤ 5

a_i ≤ 7

Subtask 3 [140 points]

There are no additional constraints.

Sample Input 1

5 5
3949 3774 3598 3469 3424

Sample Output 1

1541

The optimal solution is (height of buildings from the left) = [3949, 3950, 3951, 3952, 3953].

Sample Input 2

5 3
7 4 2 6 4

Sample Output 2

7

The optimal solution is (height of buildings from the left) = [7, 8, 2, 9, 4].

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111

	void solve(){



		ini(n);
		ini(k);
		vi morty(n);
		FOR(i,0,n)in(morty[i]);
		int tmp = inf;
		FOR(i,0,1<<n){
			int tmp1 = 0;
			FOR(i1,0,21){
				if(1<<i1 & i)tmp1++;
			}
			if(tmp1 != k)continue;
			int one  =0;
			int tmpp = 0;
			tmp1 = 0;
			FOR(i1,0,21){
				if(1<<i1 &i){
					//out(i,i1);
					if(one  == 0){
						int pos = -1;
						int max1 = 0;
						FOR(i2,0,i1){
							if(morty[i2]>max1){
								pos = i2;
								max1 = morty[i2];
							}
						}
						if(pos == -1){
							tmpp = morty[i1];
							one = 1;
						}
						else{
							tmpp = max1+1;
							tmp1+=max1-morty[i1]+1;
							one  =1;
						}
					}
					else{
						if(morty[i1]>tmpp){
							tmpp = morty[i1];
						}
						else{
							tmp1+=tmpp-morty[i1]+1;
							tmpp++;
						}
					}
					//out(tmpp);
				}
			}
			//out(tmp1,31);
			tmp = min(tmp,tmp1);
		}
		out(tmp);			







	}	























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}