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].



Sample input:
5 5
3949 3774 3598 3469 3424


Sample output:
1541

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import functools 
import sys
import bisect
import string
import math
import time
import random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

N=10**6+2
m=[0]*(N)

n,k=LI()
a=LI()
N=1<<n
ans=inf
for i in range(N):
    c=0
    t=[]
    for j in range(n):
        if (i>>j)&1:
            c+=1
            t+=[j]
    if c!=k:
        continue
    t=t[::-1]
    st=t.pop()
    alt=0
    if st==0:
        p=a[st]
    else:
        p=max(a[:st+1])+1
        alt+=max(max(a[:st])-a[st],0)
    
    while t:
        h=a[t.pop()]
        alt+=max(0,p+1-h)
        p=p+1
    if alt<ans:
        ans=alt
#        show(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import functools 
import sys
import bisect
import string
import math
import time
import random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

N=10**6+2
m=[0]*(N)

n,k=LI()
a=LI()
N=1<<n
ans=inf
for i in range(N):
    c=0
    t=[]
    for j in range(n):
        if (i>>j)&1:
            c+=1
            t+=[j]
    if c!=k:
        continue
    t=t[::-1]
    st=t.pop()
    alt=0
    if st==0:
        p=a[st]
    else:
        p=max(a[:st+1])
        alt+=max(max(a[:st])-a[st],0)
    
    while t:
        h=a[t.pop()]
        alt+=max(0,p+1-h)
        p=p+1
    if alt<ans:
        ans=alt
#        show(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
def dfs(index):
    global ans
    if index == N:
        if blst.count(1) >= K - 1:
            tmp = a[0]
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    if tmp==10**9:
                      anstmp=ans
                      break
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
ans = float('inf')
dfs(1)

print(ans)

Submission status: Wrong Answer

Solution code:
def dfs(index):
    global ans
    if index == N:
        if blst.count(1) >= K - 1:
            tmp = a[0]
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
ans = float('inf')
dfs(1)

print(ans)

Submission status: Wrong Answer

Solution code:
def dfs(index):
    global ans
    if index == N:
        print(blst)
        if blst.count(1) >= K - 1:
            tmp = a[0]
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
ans = float('inf')
dfs(1)

print(ans)

Submission status: Wrong Answer

Solution code:
def dfs(index):
    global ans
    if index == N:
        if blst.count(1) == K - 1:
            tmp = a[0]
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
ans = float('inf')
dfs(1)

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
def dfs(index):
    global ans
    if index == N:
        if blst.count(1) == K:
            tmp = a[blst.index(1)]
            anstmp = 0
            for i in range(N):
                if blst[i] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * N
ans = float('inf')
dfs(0)

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
def dfs(index):
    global ans
    if index == N:
        if blst.count(1) == K:
            tmp = a[bisect_left(a, 1)]
            anstmp = 0
            for i in range(N):
                if blst[i] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * N
ans = float('inf')
dfs(0)

print(ans - K)

Submission status: Wrong Answer

Solution code:
def dfs(index):
    global ans
    if index == N:
        if blst.count(1) == K - 1:
            tmp = a[0]
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    if tmp == 10 ** 9:
                        continue
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
ans = float('inf')
dfs(1)

print(ans)

Submission status: Wrong Answer

Solution code:
def dfs(index):
    global ans
    if index == N:
        if blst.count(1) == K - 1:
            tmp = a[0]
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
ans = float('inf')
dfs(1)

print(10 ** 9)

Submission status: Wrong Answer

Solution code:
def dfs(index):
    global ans
    if index == N:
        if blst.count(1) == K - 1:
            tmp = a[0]
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
ans = float('inf')
dfs(1)

print(0)

Submission status: Wrong Answer

Solution code:
def dfs(index):
    global ans
    if index == N:
        if blst.count(1) == K - 1:
            tmp = a[0]
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
ans = float('inf')
dfs(1)

print(ans)

Submission status: Wrong Answer

Solution code:
def dfs(index):
    global ans
    if index == N:
        if blst.count(1) == K - 1:
            tmp = a[0]
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
ans = 10 ** 20
dfs(1)

print(ans)

Submission status: Wrong Answer

Solution code:
def dfs(index):
    global ans
    if index == N :
        if blst.count(1) == K - 1:
            tmp = a[0]
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
ans = 10 ** 18
dfs(1)

print(ans)

Submission status: Wrong Answer

Solution code:
def dfs(index):
    global ans
    if index == N :
        if blst.count(1) >= K - 1:
            tmp = a1
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
a1 = a[0]
ans = 10 ** 18
dfs(1)

print(ans)

Submission status: Wrong Answer

Solution code:
def dfs(index):
    global ans
    if index == N :
        if blst.count(1) >= K - 1:
            tmp = a1
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
a1 = a[0]
ans = 10 ** 18
dfs(1)

print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b

n, k = map(int, input().split())
buildings = list(map(int, input().split()))
# 一番目は必ず見えるとして、それ以外のどれが見えるかを考える。
# どれが見えるかは、全部やればいい。
most_left = buildings[0]
buildings = buildings[1:]
ans = float('inf')
for i in range(2 ** len(buildings)):
    if bin(i).count('1') != k - 1:
        continue
    t = most_left # 初期化
    cost = 0
    for j in range(len(buildings)):
        if (i >> j) & 1:
            if t >= buildings[j]:
                cost += t - buildings[j] + 1 # 差分より、1高い必要がある。
                t += 1 #新しく増築したモノが、前のモノより高くなる。
            else:
                # より高い建物があった場合、costは増加しないが視界を塞ぐ建物は高くなる。
                t = buildings[j]
    ans = min(ans, cost)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b

n, k = map(int, input().split())
buildings = list(map(int, input().split()))
# 一番目は必ず見えるとして、それ以外のどれが見えるかを考える。
# どれが見えるかは、全部やればいい。
most_left = buildings[0]
buildings = buildings[1:]
ans = float('inf')
for i in range(2 ** len(buildings)):
    if bin(i).count('1') < k - 1:
        continue
    t = most_left # 初期化
    cost = 0
    for j in range(len(buildings)):
        if (i >> j) & 1:
            if t >= buildings[j]:
                cost += t - buildings[j] + 1 # 差分より、1高い必要がある。
                t += 1 #新しく増築したモノが、前のモノより高くなる。
            else:
                t = buildings[j]
    ans = min(ans, cost)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b

n, k = map(int, input().split())
buildings = list(map(int, input().split()))
# 一番目は必ず見えるとして、それ以外のどれが見えるかを考える。
# どれが見えるかは、全部やればいい。
most_left = buildings[0]
buildings = buildings[1:]
ans = float('inf')
for i in range(2 ** len(buildings)):
    if bin(i).count('1') < k - 1:
        continue
    t = most_left # 初期化
    cost = 0
    for j in range(len(buildings)):
        if (i >> j) & 1:
            if t >= buildings[j]:
                cost += t - buildings[j] + 1 # 差分より、1高い必要がある。
                t += 1 #新しく増築したモノが、前のモノより高くなる。
    ans = min(ans, cost)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b

n, k = map(int, input().split())
buildings = list(map(int, input().split()))
# 一番目は必ず見えるとして、それ以外のどれが見えるかを考える。
# どれが見えるかは、全部やればいい。
most_left = buildings[0]
buildings = buildings[1:]
ans = float('inf')
for i in range(2 ** len(buildings)):
    if bin(i).count('1') != k - 1:
        continue
    t = most_left
    cost = 0
    for j in range(len(buildings)):
        if (i >> j) & 1:
            if t > buildings[j]:
                cost += t - buildings[j] + 1
                t += 1
    ans = min(ans, cost)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b

n, k = map(int, input().split())
buildings = list(map(int, input().split()))
# 一番目は必ず見えるとして、それ以外のどれが見えるかを考える。
# どれが見えるかは、全部やればいい。
most_left = buildings[0]
buildings = buildings[1:]
ans = float('inf')
for i in range(2 ** len(buildings)):
    if bin(i).count('1') != k - 1:
        continue
    t = most_left
    cost = 0
    for j in range(len(buildings)):
        if (i >> j) & 1:
            if t >= buildings[j]:
                cost += t - buildings[j] + 1
                t += 1
    ans = min(ans, cost)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n, k = map(int, input().split())
a = list(map(int ,input().split()))

b = list(range(1, n))
c = combinations(b, k-1)

min_sum = 10**50
for i in c:
    sum = 0
    target = a[0] + 1
    for j in range(1, n):
        if j in i:
            sum += max(target-a[j], 0)
            target += 1
        if a[j] > target and j in i:
            target = a[j] + 1
        elif a[j] > target and j not in i:
            target = a[j]
    if sum < min_sum:
        min_sum = sum

print(min_sum)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n, k = map(int, input().split())
a = list(map(int ,input().split()))

b = list(range(1, n))
c = combinations(b, k-1)



min_sum = 10**20
for i in c:
    sum = 0
    target = a[0] + 1
    for j in range(1, n):
        if j in i:
            sum += max(target-a[j], 0)
            target += 1
        if a[j] > target and j in i:
            target = a[j] + 1
        elif a[j] > target and j not in i:
            target = a[j]
    if sum < min_sum:
        min_sum = sum

print(min_sum)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, K = MAP()
A = LIST()
INF = 10**9


def calc_cost(A, bit):
    cost = 0
    observed = 1
    prev_height = A[0]
    bit = bit | 1

    for n in range(1, N):
        if prev_height < A[n]:
            prev_height = A[n]
            observed += 1
        elif bit >> n & 1:
            costi = prev_height - A[n] + 1
            prev_height = A[n] + costi
            observed += 1
            cost += costi
    return observed, cost


ans = INF
for i in range(1 << N):
    observed, cost = calc_cost(A, i)
    if observed >= K:
        ans = min(ans, cost)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

ans = pow(10, 9)

for bit in range(1 << (N)):
    if bin(bit).count('1') < K:
        continue
    acc = 0
    pre = 0
    for i in range(N):
        if bit & (1 << i):
            if A[i] <= pre:
                acc += max(0, pre + 1 - A[i])
                pre += 1
        pre = max(pre, A[i])
    ans = min(ans, acc)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

ans = pow(10, 9)

for bit in range(1 << (N)):
    if bin(bit).count('1') < K:
        continue
    acc = 0
    pre = A[0] - 1
    for i in range(N):
        if bit & (1 << i):
            acc += max(0, pre + 1 - A[i])
            pre += 1
        pre = max(pre, A[i])
    ans = min(ans, acc)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

ans = pow(10, 9)

for bit in range(1 << (N)):
    if bin(bit).count('1') < K:
        continue
    acc = 0
    pre = A[0] - 1
    for i in range(N):
        if bit & (1 << i):
            if pre < A[i]:
                pre = A[i]
            else:
                acc += pre + 1 - A[i]
                pre += 1
        else:
            pre = max(pre, A[i])
    ans = min(ans, acc)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

ans = pow(10, 9)

for bit in range(1 << (N)):
    if bin(bit).count('1') < K:
        continue
    acc = 0
    pre = A[0] - 1
    for i in range(N):
        if bit & (1 << i):
            if pre < A[i]:
                pre = A[i]
            else:
                acc += pre + 1 - A[i]
                pre += 1
    ans = min(ans, acc)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

ans = pow(10, 9)

for bit in range(1 << (N)):
    if bin(bit).count('1') < K:
        continue
    acc = 0
    pre = A[0] - 1
    flag = True
    for i in range(N):
        if bit & (1 << i):
            if pre < A[i]:
                pre = A[i]
            else:
                acc += pre + 1 - A[i]
                pre += 1
        else:
            if pre <= A[i]:
                flag = False
                break
    if flag:
        ans = min(ans, acc)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

ans = pow(10, 9)

for bit in range(1 << (N)):
    if bin(bit).count('1') < K:
        continue
    acc = 0
    pre = A[0] - 1
    flag = True
    for i in range(N):
        if bit & (1 << i):
            if pre < A[i]:
                pre = A[i]
            else:
                acc += pre + 1 - A[i]
                pre += 1
        else:
            if pre < A[i]:
                flag = False
                break
    if flag:
        ans = min(ans, acc)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

ans = pow(10, 8)

for bit in range(1 << (N)):
    if bin(bit).count('1') < K:
        continue
    acc = 0
    pre = A[0] - 1
    flag = True
    for i in range(N):
        if bit & (1 << i):
            if pre < A[i]:
                pre = A[i]
            else:
                acc += pre + 1 - A[i]
                pre = pre + 1
        else:
            if pre < A[i]:
                flag = False
                break
    if flag:
        ans = min(ans, acc)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

ans = pow(10, 8)

for bit in range(1 << (N)):
    if bin(bit).count('1') < K:
        continue
    acc = 0
    pre = A[0] - 1
    for i, a in enumerate(A[:]):
        if bit & (1 << i):
            if pre < a:
                pre = a
            else:
                acc += pre + 1 - a
                pre = pre + 1
        else:
            if pre < a:
                pre = a

    ans = min(ans, acc)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

ans = pow(10, 8)

for bit in range(1 << N):
    if bin(bit).count('1') < K:
        continue
    acc = 0
    pre = A[0] - 1
    for i in range(N):
        if bit & (1 << i):
            acc += max(0, pre + 1 - A[i])
            pre = max(A[i], pre + 1)
    ans = min(ans, acc)
print(int(ans))

Submission status: Wrong Answer

Solution code:
print(0)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(x) for x in input().split()]
_min = 1145141919810
for i in range(2**(n-1)):
    ctr = 0
    val = 0
    h_max = a[0]
    for j in range(n-1):
        if (i>>j)&1:
            ctr+=1
            h_max = h_max+1 if h_max>=a[j+1] else a[j+1]
            val+=h_max-a[j+1]
        if h_max<a[j+1]:
            h_max = a[j+1]
    if ctr==k-1 and val<_min and h_max<=10**9:
        _min = val
print(_min)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(x) for x in input().split()]
_min = 1145141919810
for i in range(2**(n-1)):
    ctr = 0
    val = 0
    h_max = a[0]
    for j in range(n-1):
        if h_max<a[j+1]:
            h_max = a[j+1]
        if (i>>j)&1:
            ctr+=1
            h_max = h_max+1 if h_max>=a[j+1] else a[j+1]
            val+=h_max-a[j+1]
    if ctr==k-1 and val<_min and h_max<=10**9:
        _min = val
print(_min)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(x) for x in input().split()]
_min = 1145141919810
for i in range(2**(n-1)):
    ctr = 0
    val = 0
    flag = 0
    h_max = a[0]
    for j in range(n-1):
        if (i>>j)&1:
            ctr+=1
            h_max = h_max+1 if h_max>=a[j+1] else a[j+1]
            val+=h_max-a[j+1]
            if ctr>=k-1:
                flag=1
                break
    if val<_min and flag and h_max<=10**9:
        _min = val
print(_min)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(x) for x in input().split()]
_min = 1145141919810
for i in range(2**(n-1)):
    ctr = 0
    val = 0
    flag = 0
    h_max = a[0]
    for j in range(n-1):
        if (i>>j)&1:
            ctr+=1
            h_max = h_max+1 if h_max>=a[j+1] else a[j+1]
            val+=h_max-a[j+1]
            if ctr>=k-1:
                flag=1
                break
    if val<_min and flag:
        _min = val
print(_min)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = float('inf')
for i in range(1<<(n-1)):
    count = 0
    for j in range(n-1):
        if i>>j&1:
            count += 1
    if count < k - 1:
        continue
    minLim = a[0] + 1
    cost = 0
    for j in range(n-1):
        if i>>j&1:
            if a[j+1] < minLim:
                cost += minLim - a[j+1]
                minLim += 1
            else:
                minLim = a[j+1] + 1
    ans = min(ans, cost)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = float('inf')
for i in range(1<<(n-1)):
    count = 0
    for j in range(n-1):
        if i>>j&1:
            count += 1
    if count < k - 1:
        continue
    minLim = a[0] + 1
    cost = 0
    for j in range(n-1):
        if i>>j&1:
            if a[j+1] < minLim:
                cost += minLim - a[j+1]
                minLim += 1
            else:
                minLim += a[j+1] + 1
    ans = min(ans, cost)
print(ans)