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:
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 ctr>=(k-1) and val<=_min:
        _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 (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:
        _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 = 10**100
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 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 (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
    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 and val<_min:
        _min = val
print(_min)

Submission status: Wrong Answer

Solution code:
def f(i):
    global m
    if i == n:
        if sum(s) == k and s[0] == 1:
            h = [0] * n
            for i in range(n):
                if i == 0:
                    h[0] = a[0]
                    g = 0
                else:
                    if s[i] == 0:
                        if h[g] < a[i]:
                            h[g] = a[i]
                        h[i] = a[i]
                    else:
                        if h[g] > a[i]:
                            h[i] = h[g] + 1
                        else:
                            h[i] = a[i]
                        g = i
            c = sum(h) - sum(a) 
            if c < m:
                m = c
        return         
    f(i + 1)
    s[i] = 1
    f(i + 1)
    s[i] = 0

n, k = map(int, input().split())
a = list(map(int, input().split()))
s = [0 for _ in range(n)]
m = 2 * 10 ** 10
f(0)
print(m)

Submission status: Wrong Answer

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

# 一番左はいつも見えている
ans = (10**9)*15
for i in range(2**(n-1)):
    pattern = []
    for j in range(n-1):
        if (i >> j) & 1:
            pattern.append(j+1)
    if len(pattern) < (k-1): continue
    count = 0
    prev = a[0]
    for l in range(k-1):
        #print(pattern, prev)
        if a[pattern[l]] <= prev:
            extended = prev + 1
            count += (extended - a[pattern[l]])
            prev = extended
        else:
            prev = a[pattern[l]]
    #print(count)
    ans = min(ans, count)
print(0 if k == 1 else ans)

Submission status: Wrong Answer

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

# 一番左はいつも見えている
ans = (10**9)*15
for i in range(2**(n-1)):
    pattern = []
    for j in range(n-1):
        if (i >> j) & 1:
            pattern.append(j+1)
    if len(pattern) != (k-1): continue
    count = 0
    prev = a[0]
    for l in range(k-1):
        #print(pattern, prev)
        if a[pattern[l]] <= prev:
            extended = prev + 1
            count += (extended - a[pattern[l]])
            prev = extended
        else:
            prev = a[pattern[l]]
    #print(count)
    ans = min(ans, count)
print(0 if k == 1 else ans)

Submission status: Wrong Answer

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

# 一番左はいつも見えている
ans = 10**9
for i in range(2**(n-1)):
    pattern = []
    for j in range(n-1):
        if (i >> j) & 1:
            pattern.append(j+1)
    if len(pattern) != (k-1): continue
    count = 0
    prev = a[0]
    for l in range(k-1):
        #print(pattern, prev)
        if a[pattern[l]] <= prev:
            extended = prev + 1
            count += (extended - a[pattern[l]])
            prev = extended
        else:
            prev = a[pattern[l]]
    #print(count)
    ans = min(ans, count)
print(0 if k == 1 else ans)

Submission status: Wrong Answer

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

# 一番左はいつも見えている
ans = (10**9)*15
for i in range(2**(n-1)):
    pattern = []
    for j in range(n):
        if (i >> j) & 1:
            pattern.append(j+1)
    if len(pattern) != (k-1): continue
    count = 0
    prev = a[0]
    for l in range(k-1):
        #print(pattern, prev)
        if a[pattern[l]] <= prev:
            extended = prev + 1
            count += (extended - a[pattern[l]])
            prev = extended
        else:
            prev = a[pattern[l]]
    #print(count)
    ans = min(ans, count)
print(0 if k == 1 else ans)

Submission status: Wrong Answer

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

# 一番左はいつも見えている
ans = (10**9)*15
for i in range(2**(n-1)):
    pattern = []
    for j in range(n):
        if (i >> j) & 1:
            pattern.append(j+1)
    if len(pattern) != (k-1): continue
    count = 0
    prev = a[0]
    for l in range(k-1):
        #print(pattern, prev)
        if a[pattern[l]] <= prev:
            extended = prev + 1
            count += (extended - a[pattern[l]])
            prev = extended
        else:
            prev = a[pattern[l]]
    #print(count)
    ans = min(ans, count)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
a_list = list(map(int,input().split()))

# 建物iをミられる高さにするかいなかのbit探索

ans = np.inf

for byte in range(pow(2,N-1)):
    height = a_list[0]
    cost = 0
    if bin(byte).count("1")>=K-1:
        for i in range(N-1):
            if not (byte & 1<<i)==0: # i番目を見る場合
                cost += max(0, height + 1 - a_list[i+1])
                height = max(height + 1, a_list[i+1])
        if cost < ans:
            ans = cost
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a_list = list(map(int,input().split()))

# 建物iをミられる高さにするかいなかのbit探索

ans = 100010001000100010001000100010001000

for byte in range(pow(2,N-1)):
    height = a_list[0]
    cost = 0
    if bin(byte).count("1")>=K-1:
        for i in range(N-1):
            if not (byte & 1<<i)==0: # i番目を見る場合
                cost += max(0, height + 1 - a_list[i+1])
                height = max(height + 1, a_list[i+1])
        if cost < ans:
            ans = cost
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a_list = list(map(int,input().split()))

# 建物iをミられる高さにするかいなかのbit探索

ans = 10001000100010001000

for byte in range(pow(2,N-1)):
    height = a_list[0]
    cost = 0
    if bin(byte).count("1")>=K-1:
        for i in range(N-1):
            if not (byte & 1<<i)==0: # i番目を見る場合
                cost += max(0, height + 1 - a_list[i+1])
                height = max(height + 1, a_list[i+1])
        if cost < ans:
            ans = cost
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a_list = list(map(int,input().split()))

# 建物iをミられる高さにするかいなかのbit探索

ans = pow(10,10)

for byte in range(pow(2,N-1)):
    height = a_list[0]
    cost = 0
    if bin(byte).count("1")>=K-1:
        for i in range(N-1):
            if not (byte & 1<<i)==0: # i番目を見る場合
                cost += max(0, height + 1 - a_list[i+1])
                height = max(height + 1, a_list[i+1])
        if cost < ans:
            ans = cost
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    
    ans=10**9
    for bit in range(1<<n):
        s=set()
        for i in range(n):
            if (bit>>i)&1:
                s.add(i)
                
        if len(s)!=k:
          continue       
        
        b=a.copy()
        M=0
        cost=0
        for i in range(n):
            if (i in s) and b[i]<=M:               
                cost+=M-b[i]+1
                b[i]=M+1
                M+=1
            else:
                M=max(M,b[i])
        ans=min(ans,cost)
        
    print(ans)
 
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
# import math
# import bisect
#import numpy as np
import itertools
# import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    cmb = list(itertools.combinations([i for i in range(1, n)], k-1))
    ans = INF

    if k > 1:
            for ele in cmb:
                prc = 0
                prev = a[0]

                for idx in ele:
                    cur = a[idx]
                    if cur - prev <= 0:
                        prc += prev - cur + 1
                        cur = prev + 1
                    prev = cur

                for i in range(n):
                    if i != idx:
                        if a[i] >= prev:
                            break
                else:
                    ans = min(ans, prc)
    else:
        ans = 0

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# import math
# import bisect
#import numpy as np
import itertools
# import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    cmb = list(itertools.combinations([i for i in range(1, n)], k-1))
    ans = INF

    if k > 1:
            for ele in cmb:
                prc = 0
                prev = a[0]

                for idx in ele:
                    cur = a[idx]
                    if cur - prev <= 0:
                        prc += prev - cur + 1
                        cur = prev + 1
                    prev = cur

            if prev > max(a[idx:]):
                ans = min(ans, prc)
    else:
        ans = 0

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# import math
# import bisect
#import numpy as np
import itertools
# import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    cmb = list(itertools.combinations([i for i in range(1, n)], k-1))
    ans = INF

    if k > 1:
            for ele in cmb:
                prc = 0
                prev = a[0]

                for idx in ele:
                    cur = a[idx]
                    if cur - prev <= 0:
                        prc += prev - cur + 1
                        cur = prev + 1
                    prev = cur

            if prev >= max(a):
                ans = min(ans, prc)
    else:
        ans = 0

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# import math
# import bisect
#import numpy as np
import itertools
# import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    cmb = list(itertools.combinations([i for i in range(1, n)], k-1))
    ans = INF

    if k > 1:
            for ele in cmb:
                prc = 0
                prev = a[0]

                for idx in ele:
                    cur = a[idx]
                    if cur - prev <= 0:
                        prc += prev - cur + 1
                        cur = prev + 1
                    prev = cur
                if prev >= max(a):
                    ans = min(ans, prc)
    else:
        ans = 0

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# import math
# import bisect
#import numpy as np
import itertools
# import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    cmb = list(itertools.combinations([i for i in range(1, n)], k-1))
    ans = INF

    for ele in cmb:
        prc = 0
        prev = a[0]
        for idx in ele:
            cur = a[idx]
            if cur - prev <= 0:
                prc += prev - cur + 1
                cur = prev + 1
            prev = cur
        ans = min(ans, prc)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
'''
https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
'''
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil
    import copy

    #mod = 1000000007

    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    res = 10**17


    for i in combinations(range(1, n), k-1):
        i = (0,) + i
        total = 0
        b = a[:]
        for j in range(k-1):
            if b[i[j]]>=b[i[j+1]]:
                total += b[i[j]]-b[i[j+1]]+1
                b[i[j+1]] = b[i[j]]+1
        res = min(res, total)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
'''
https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
'''
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil
    import copy

    #mod = 1000000007

    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    res = 10**17


    for comb in combinations(range(1, n), k-1):
        i = (0,) + comb
        total = 0
        b = copy.copy(a)
        for j in range(k-1):
            if b[i[j]]>=b[i[j+1]]:
                total += b[i[j]]-b[i[j+1]]+1
                b[i[j+1]] = b[i[j]]+1
        res = min(res, total)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import copy
    from itertools import combinations

    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    res = 10**17

    for i in combinations(range(1, n), k-1):
        i = (0,) + i
        total = 0
        b = copy.copy(a)
        for j in range(k-1):
            if b[i[j]]>=b[i[j+1]]:
                total += b[i[j]]-b[i[j+1]]+1
                b[i[j+1]] = b[i[j]]+1
        res = min(res, total)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil
    import copy

    #mod = 1000000007

    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    res = 10**17
    for i in range(2**n):
        total, m, cnt = 0, 0, 0
        for j in range(n):
            if(i>>j) & 1:
                cnt += 1
                total += max(m-a[j]+1, 0)
                m = max(m, a[j])
            else:
                m = max(m, a[j])
        if cnt == k:
            res = min(res, total)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
'''
https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
'''
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil
    import copy

    #mod = 1000000007

    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    res = 10**100
    for i in combinations(range(1, n), k-1):
        i = (0,) + i
        total = 0
        b = copy.copy(a)
        for j in range(k-1):
            if b[i[j]]>=b[i[j+1]]:
                total += b[i[j]]-b[i[j+1]]+1
                b[i[j+1]] = b[i[j]]+1
        res = min(res, total)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
'''
https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
'''
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil
    import copy

    #mod = 1000000007

    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    res = 10**100
    for i in combinations(range(1, n), k-1):
        i = (0,) + i
        total = 0
        b = copy.copy(a)
        for j in range(k-1):
            #diff += a[i[j]]-a[i[j+1]]
            total += max(0, b[i[j]]-b[i[j+1]]+1)
            if b[i[j]]>=b[i[j+1]]:
                b[i[j+1]] = b[i[j]]+1
        res = min(res, total)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
'''
https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
'''
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil
    import copy

    #mod = 1000000007

    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    res = 10**17
    for i in combinations(range(1, n), k-1):
        i = (0,) + i
        total = 0
        b = copy.copy(a)
        for j in range(k-1):
            #diff += a[i[j]]-a[i[j+1]]
            total += max(0, b[i[j]]-b[i[j+1]]+1)
            if b[i[j]]>=b[i[j+1]]:
                b[i[j+1]] = b[i[j]]+1
        res = min(res, total)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
'''
https://atcoder.jp/contests/s8pc-4/tasks/s8pc_4_b
'''
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil
    import copy

    #mod = 1000000007

    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    res = 10**17
    for i in combinations(range(1, n), k-1):
        i = (0,) + i
        total = 0
        b = copy.copy(a)
        for j in range(k-1):
            #diff += a[i[j]]-a[i[j+1]]
            total += max(0, b[i[j]]-b[i[j+1]]+1)
            b[i[j+1]] = b[i[j]]+1
        res = min(res, total)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
inf = 1000000000

def main():
    n, k = map(int, input().split())
    num_list = list(map(int, input().split()))

    ans = inf

    for bit in range(2**n):
        if bin(bit).count('1') != k:
            continue
        tmp = 0
        max_hight = 0
        for i in range(n):
            if bit & (1 << i) == 0:
                if max_hight < num_list[i]:
                    max_hight = num_list[i]
                # max_hight = max(max_hight, num_list[i])
                continue
            if max_hight >= num_list[i]:
                tmp += max_hight - num_list[i] + 1
                max_hight += 1
            else:
                max_hight = num_list[i]
            
        if ans > tmp:
            ans = tmp
        # ans = min(ans, tmp)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
inf = 1000000000

def main():
    n, k = map(int, input().split())
    num_list = list(map(int, input().split()))

    ans = inf

    for bit in range(2**n):
        if bin(bit).count('1') != k:
            continue
        tmp = 0
        max_hight = 0
        for i in range(n):
            if bit & (1 << i) == 0:
                max_hight = max(max_hight, num_list[i])
                continue
            if max_hight >= num_list[i]:
                tmp += max_hight - num_list[i] + 1
                max_hight += 1
            else:
                max_hight = num_list[i]
            
        if ans > tmp:
            ans = tmp
        # ans = min(ans, tmp)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import product

inf = 1000000000

def main():
    n, k = map(int, input().split())
    num_list = list(map(int, input().split()))

    ans = inf

    # for bit in list(product([0, 1], repeat = n)):
    for bit in range(2**n):
        if bin(bit).count('1') != k:
            continue
        tmp = 0
        max_hight = 0
        for i in range(n):
            if bit & (1 << i) == 0:
                max_hight = max(max_hight, num_list[i])
                continue
            if max_hight >= num_list[i]:
                tmp += max_hight - num_list[i] + 1
                max_hight += 1
            else:
                max_hight = num_list[i]
            
        ans = min(ans, tmp)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import product

inf = 1000000000

def main():
    n, k = map(int, input().split())
    num_list = list(map(int, input().split()))

    ans = inf

    for bit in list(product([0, 1], repeat = n)):
        count = bit.count(1)
        if count != k:
            continue
        tmp = 0
        max_hight = 0
        for i in range(n):
            if bit[i] != 1:
                max_hight = max(max_hight, num_list[i])
                continue
            if max_hight >= num_list[i]:
                tmp += max_hight - num_list[i] + 1
                max_hight += 1
            else:
                max_hight = num_list[i]
            
        ans = min(ans, tmp)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import product

inf = 1000000000

def main():
    n, k = map(int, input().split())
    num_list = list(map(int, input().split()))

    ans = inf

    for bit in list(product([0, 1], repeat = n)):
        count = bit.count(1)
        if count < k:
            continue
        tmp = 0
        max_hight = 0
        for i in range(n):
            if bit[i] != 1:
                max_hight = max(max_hight, num_list[i])
                continue
            if max_hight >= num_list[i]:
                tmp += max_hight - num_list[i] + 1
                max_hight += 1
            else:
                max_hight = num_list[i]
            
        ans = min(ans, tmp)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import product   # bit全探索: list(itertools.product([0,1], repeat=n))

inf = 1000000000    # 1,000,000,000

def main():
    n, k = map(int, input().split())
    num_list = list(map(int, input().split()))

    ans = inf

    for bit in list(product([0, 1], repeat = n)):
        count = bit.count(1)
        if count < k:
            continue
        if bit[0] != 1:
            continue
        tmp = 0
        max_hight = 0
        for i in range(n):
            if bit[i] != 1:
                max_hight = max(max_hight, num_list[i])
                continue
            if max_hight >= num_list[i]:
                tmp += max_hight - num_list[i] + 1
                max_hight += 1
            else:
                max_hight = num_list[i]
            
        ans = min(ans, tmp)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import product   # bit全探索: list(itertools.product([0,1], repeat=n))

inf = 1000000000    # 1,000,000,000

def main():
    n, k = map(int, input().split())
    num_list = list(map(int, input().split()))

    ans = inf

    for bit in list(product([0, 1], repeat = n)):
        count = bit.count(1)
        if count < k:
            continue
        if bit[0] != 1:
            continue
        tmp = 0
        max_hight = num_list[0]
        for i in range(1,n):
            if bit[i] != 1:
                max_hight = max(max_hight, num_list[i])
                continue
            if max_hight >= num_list[i]:
                add_hight = max_hight - num_list[i] + 1
                tmp += add_hight
                max_hight += 1
            else:
                max_hight = num_list[i]
            
        ans = min(ans, tmp)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import product   # bit全探索: list(itertools.product([0,1], repeat=n))
from copy import deepcopy   # 配列のコピー: B = deepcopy(A)

inf = 1000000000    # 1,000,000,000

def main():
    n, k = map(int, input().split())
    num_list = list(map(int, input().split()))

    num_list_copy = deepcopy(num_list)

    ans = inf

    for bit in list(product([0, 1], repeat = n)):
        count = bit.count(1)
        if count < k:
            continue
        if bit[0] != 1:
            continue
        tmp = 0
        max_hight = num_list[0]
        for i in range(1,n):
            if bit[i] != 1:
                max_hight = max(max_hight, num_list[i])
                continue
            if max_hight >= num_list[i]:
                add_hight = max_hight - num_list[i] + 1
                num_list[i] += add_hight
                tmp += add_hight
            max_hight = max(max_hight, num_list[i])
            
        num_list = deepcopy(num_list_copy)
        ans = min(ans, tmp)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import product   # bit全探索: list(itertools.product([0,1], repeat=n))
from copy import deepcopy   # 配列のコピー: B = deepcopy(A)

inf = 1000000000    # 1,000,000,000

def main():
    n, k = map(int, input().split())
    num_list = list(map(int, input().split()))

    num_list_copy = deepcopy(num_list)

    ans = inf

    for bit in list(product([0, 1], repeat = n)):
        count = bit.count(1)
        if count < k:
            continue
        if bit[0] != 1:
            continue
        # print(bit)
        tmp = 0
        max_hight = 0
        for i in range(n-1):
            max_hight = max(max_hight, num_list[i])
            if bit[i] != 1:
                continue
            x = 1
            while(bit[i+x] != 1):
                if i + x >= n - 1:
                    x = n - i - 1
                    break
                x += 1
            if max_hight >= num_list[i+x]:
                add_hight = max_hight - num_list[i+x] + 1
                num_list[i+x] += add_hight
                tmp += add_hight
        num_list = deepcopy(num_list_copy)
        ans = min(ans, tmp)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import product   # bit全探索: list(itertools.product([0,1], repeat=n))
from copy import deepcopy   # 配列のコピー: B = deepcopy(A)

inf = 1000000000    # 1,000,000,000

def main():
    n, k = map(int, input().split())
    num_list = list(map(int, input().split()))

    num_list_copy = deepcopy(num_list)

    ans = inf

    for bit in list(product([0, 1], repeat = n)):
        count = bit.count(1)
        if count < k:
            continue
        if bit[0] != 1:
            continue
        # print(bit)
        tmp = 0
        for i in range(n-1):
            if bit[i] != 1:
                continue
            x = 1
            while(bit[i+x] != 1):
                if i + x >= n - 1:
                    x = n - i - 1
                    break
                x += 1
            if num_list[i] >= num_list[i+x]:
                add_hight = num_list[i] - num_list[i+x] + 1
                num_list[i+x] += add_hight
                tmp += add_hight
        num_list = deepcopy(num_list_copy)
        ans = min(ans, tmp)
    
    print(ans)

if __name__ == '__main__':
    main()