Problem:


Score : 300 points

Problem Statement

There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.

On this sequence, Snuke can perform the following operation:

Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.

Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.
Find the minimum number of operations required.
It can be proved that, Under the constraints of this problem, this objective is always achievable.

Constraints

2 \leq K \leq N \leq 100000

A_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of operations required.

Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

One optimal strategy is as follows:

In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.

In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.

Sample Input 2

3 3
1 2 3

Sample Output 2

1

Sample Input 3

8 3
7 3 1 8 4 6 2 5

Sample Output 3

4



Sample input:
4 3
2 3 1 4


Sample output:
2

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
P1=0
for i in range(N):
    if A[i]==1:
        P1=i
        break
L=P1
R=N-1-P1
if L>=K-1 and R>=K-1:
    ans=0
    while(True):
        L-=K-1
        ans+=1
        if L<=0:
            break
    while(True):
        R-=K-1
        ans+=1
        if R<=0:
            break
    print(ans)
else:
    M=N-1
    ans=0
    while(True):
        M-=K-1
        ans+=1
        if M<=0:
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, A):
    for i, a in enumerate(A):
        if a == 1:
            break

    i += 1
    K -= 1
    ans = 0
    if i != 1:
        ans += int(math.ceil(i / K))

    if i != N:
        ans += int(math.ceil(((N - i) / K)))

    if ((i % K) + ((N - i) % K)) <= K and i != 1 and i != N:
        ans -= 1

    return ans


def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(n):
    if a[i] == 1:
        left = i
        break
right = n - i - 1

if left % (k - 1) > 0 and right % (k - 1) > 0:
    r = 1
else:
    r = 0
print(math.ceil(left/(k-1)) + math.ceil(right/(k-1)) - r)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
k = (a[0] + 1) // (a[1] - 1)
 
if a[0] == a[1]:
	k -= 1
print(k)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
p = A.index(1)
print((p+1)//(K-1)+(N-p)//(K-1))

Submission status: Wrong Answer

Solution code:
input_line = input().split()

num_array = int(input_line[0])
num_equal = int(input_line[1])

input_line = input()

# from forward

if num_array % num_equal == 0:
    if num_array == num_equal:
        print("1")
    else:
        print(num_array // (num_equal - 1))

else:
    print(num_array // (num_equal - 1))

Submission status: Wrong Answer

Solution code:
n,k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
x,ans = a.index(1),0
if x>=k and n-x-1>=k: print(max(0,x-1)//(k-1)+max(0,n-x-2)//(k-1)+2)
elif x>=k or n-x-1>=k: print((max(0,n-k-1))//(k-1)+2)
elif n==k: print(1)
else: print(2)

Submission status: Wrong Answer

Solution code:
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

N, K = rdi()
A = rdi()

for i in range(len(A)):
        if A[i] == 1:
                break
assert A[i] == 1

l = i
r = N-i-1

if K > 1:
        c = (l+K-2) / (K-1) + (r+K-2) / (K-1)
else:
        c = l + r
print c

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
a=list(map(int, input().split()))
if n==k:
    print(1)
elif n%k==0:
    print(n//(k-1)+1)
else:
    print(n//(k-1))

Submission status: Wrong Answer

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

if k == n:
	print(1)
elif 2 * k > n:
	print(2)
else:
	one_index = a.index(1)

	if one_index == 0 or one_index == n - 1:
		print((n - 2) // (k - 1) + 1)
	elif one_index >= k - 1 or n - one_index - 1 >= k - 1:
		print((one_index - 1) // (k - 1) + (n - one_index - 2) // (k - 1) + 2)
	else:
		print((n - 2) // (k - 1) + 1)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0

k = (a[0] + 1) // (a[1] - 1)

print(k)

Submission status: Wrong Answer

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

ans = n - k + 1
i1 = -1
for i in range(n):
    if a[i] == 1:
        i1 = i
        break
for i in range(max(i1 - k, 0), i1 + 1):
    ans = min(ans, max(i + 1, max(n - i - k + 1, 1)))

print(ans)

Submission status: Wrong Answer

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

nums_len = len(nums)

count = 0

index = nums.index(1)

former = index
later = nums_len - index - 1

former_c = (former + (k-2)) // (k-1)
later_c = (later + (k-2)) // (k-1)

print(former_c + later_c)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

def cnt(C, K):
    c = C // (K - 1)
    if C % (K - 1) > 0:
        c += 1
    return c


def main():
    N, K = [int(e) for e in input().split(' ')]
    A = [int(e) for e in input().split(' ')]
    assert len(A) == N

    op = A.index(1)

    ans = cnt(op, K) + cnt(N - op - 1, K)
    if op < K or (N - op - 1) < K:
        ans = min(ans, cnt(N - 1, K))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
a=0
for i in range(N):
    if A[i]==1:
        a=i
        break
if a <=K-1:
    print(math.ceil((N-K)/(K-1))+1)
    sys.exit()
if N-K<=a:
    print(math.ceil((N-K)/(K-1))+1)
    sys.exit()
print(math.ceil(a/(K-1))+math.ceil((N-a-1)/(K-1)))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


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


def kiriage(a, b):
    return (a + b - 1) // b

i = A.index(1)

print(kiriage(i, K-1) + kiriage(N-i-1, K-1))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
s=list(input())
if N==K:
    print(1)
else:
    print((N-1)//(K-1)+1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, A):
    for i, a in enumerate(A):
        if a == 1:
            break

    i += 1
    K -= 1
    ans = 0
    ans += int(math.ceil(i / K))
    ans += int(math.ceil(((N - i) / K)))

    if ((i % K) + ((N - i) % K)) <= K:
        ans -= 1

    return ans


def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# encoding:utf-8

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

	print(-(-n // (k - 1)))

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
one = a.index(1)
# 個数
hidari = one
migi = n - (one+1)
# k回ためす
mini = 10*10
for i in range(k):
    hidarii = hidari - i
    migii = migi - (k - 1 - i)
    if hidarii < 0 or migii < 0:
        continue
    if hidarii == 0:
        cnt = (migii - 1)//(k-1) + 1
    elif migii == 0:
        cnt = (hidarii - 1)//(k-1) + 1
    else:
        cnt = (migii - 1)//(k-1) + 1 + (hidarii - 1)//(k-1) + 1
    mini = min(cnt, mini)
print(mini + 1)

Submission status: Wrong Answer

Solution code:
import math

N,K=map(int, raw_input().split())
A=map(int, raw_input().split())
i=A.index(1)
if N==K:
    left,right=0,0
    ans=1

else:
    if i<K:
        left=1
        i=K-1
    else:
        left= int(math.ceil((i)/float(K-1)))
    right= int(math.ceil((N-i-1)/float(K-1)))
    ans=left+right
print ans

Submission status: Wrong Answer

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

if k == n:
	print(1)
elif 2 * k > n:
	print(2)
else:
	one_index = a.index(1)

	if one_index == 0 or one_index == n - 1:
		print((n - 2) // (k - 1) + 1)
	else:
		print((one_index - 1) // (k - 1) + (n - one_index - 2) // (k - 1) + 2)

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
idx = 0
for i, a in enumerate(A):
	if a == 1:
		idx = i

print(ceil(idx / (K-1)) + ceil((N - idx - 1) / (K - 1)))

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int, input().split())
array = [int(x) for x in input().split()]

tmp = array.index(1)
res1 = math.ceil(tmp/k) if tmp != 0 else 0
res2 = ((n-tmp)//k+1 if (n-tmp)% k == 0 else math.ceil((n-tmp)/k)) if n > k else 1

print(res1+res2)

Submission status: Wrong Answer

Solution code:
from math import ceil

N, K = map(int, input().split())
As = list(map(int, input().split()))

if N == K:
    print(1)
else:
    i1 = As.index(1)
    print(ceil(i1 / (K-1)) + ceil((N-1-i1) / (K-1)))

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
m = a.index(1)
m0 = m //(k-1)
if m%(k-1) != 0:
    m0 += 1
m1 = (n-m-1)//(k-1)
if (n-m-1)%(k-1) != 0:
    m1 += 1
ans = m0+m1
print(ans)

Submission status: Wrong Answer

Solution code:
def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def main():
    N, K = lii()
    a = lii()
    min_ix = None
    for i, v in enumerate(a):
        if v == 1:
            min_ix = i
            break

    def t(n, k):
        if n <= 0: return 0

        ans = n // k
        if n % k:
            ans += 1
        return ans

    if N-1 - min_ix >= K-1 and min_ix >= K-1:
        return t(min_ix, K-1) + t(N-1 - min_ix, K-1)

    elif min_ix < K-1:
        d = K-1 - min_ix
        return 1 + t(N-1 - min_ix - d, K-1)

    elif N-1 - min_ix < K-1:
        d = K-1 - (N-1 - min_ix)
        return t(min_ix - d, K-1) + 1


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

def cnt(C, K):
    c = C // (K - 1)
    if C % (K - 1) > 0:
        c += 1
    return c


def main():
    N, K = [int(e) for e in input().split(' ')]
    A = [int(e) for e in input().split(' ')]
    assert len(A) == N

    op = A.index(1)

    print(cnt(op, K) + cnt(N - op - 1, K))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
j = -1
num = float("inf")
for i in range(n):
    if a[i] < num:
        num = a[i]
        j = i

if i != 0 and i // (m - 1) == 0:
    print(1 + (i + 1) // (m - 1) + (n - i - 1) // (m - 1))
elif i != n - 1 and (n - i - 1) // (m - 1) == 0:
    print(1 + (i + 1) // (m - 1) + (n - i - 1) // (m - 1))
else:
    print((i + 1) // (m - 1) + (n - i - 1) // (m - 1))

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))

X = A.index(min(A))
L = X
R = N - X - 1

print(int(ceil(L / (K-1)) + ceil(R / (K-1))))

Submission status: Wrong Answer

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

for i in range(n):
    if a[i] == 1:
        left = i
        break
right = n - i - 1

print(math.ceil(left/(k-1)) + math.ceil(right/(k-1)) )

Submission status: Wrong Answer

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

one_index = a.index(1)

if one_index == 0 or one_index == n - 1:
	print((n - 2) // (k - 1) + 1)
else:
	print((one_index - 1) // (k - 1) + (n - one_index - 2) // (k - 1) + 2)

Submission status: Wrong Answer

Solution code:
n,k=map(int,raw_input().split())
N=map(int,raw_input().split())
t=N.index(1)+1
print (n-t+1)/(k-1)+t/(k-1)

Submission status: Wrong Answer

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

m = min(xs)

i = 0

ans = 0

while i < n:
    if xs[i] == m:
        i += 1
        continue
    else:
        ans += 1
        i += k - 1


print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, raw_input().split())
    list = map(int, raw_input().split())
    minindex = min(zip(list, range(len(list))))[1]
    mae = list[:minindex]
    ato = list[minindex:]
    print len(mae)/(K-1) + len(ato)/(K-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# encoding:utf-8

def main():
	n, k = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	
	s = nums.index(1)

	n_l = s
	n_r = n - s - 1
	#print(n_l, n_r) 

	print(-(-n_l // (k - 1)) -(-n_r // (k - 1)))

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
a = set(a)
ans = 0
if len(a) == 1:
  print(0)
else:
  naga = len(a)-K
  if naga <= 0:
    print(1)
  else:
    K = K-1
    ans += 1
    ans += (naga//K) + 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
a=list(map(int, input().split()))
b=a.index(1)
print((b+1)//(k-1)+(n-b)//(k-1))

Submission status: Wrong Answer

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

for i, j in enumerate(a):
    if(j == 1): break

count = 0
tmp = i
while(i > 0):
    count += 1
    i -= (k - 1)

i = tmp
while(i < n - 1):
    count += 1
    i += (k - 1)

print(count)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
for i in range(a[0]):
	if b[i] == 1:
		c = i

k = (a[0] + 1) // a[1]

if a[0] != a[1]:
  k += 1

print(k)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
p = A.index(1)
print(p//(K-1)+(N-p)//(K-1))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
P1=0
for i in range(N):
    if A[i]==1:
        P1=i
        break
L=-(-P1//(K-1))
R=-((-N+P1+1)//(K-1))
print(L+R)

Submission status: Wrong Answer

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

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

b = min(a)

lft = 0
rgt = 0
for i in range(len(a)):
    if a[i] == b:
        lft = i
        break

ret = 0
i = 0
for i in range(len(a)):
    if a[i] == b:
        continue
    for j in range(k - 1):
        if not i + j < n:
            break
        a[i+j] = b
    ret += 1

print(ret)

Submission status: Wrong Answer

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

X = A.index(min(A))
L = X
R = N - X

print(int((L / (K-1)) + (R // (K-1))))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
src = list(map(int,input().split()))
one = src.index(1)

right = N-1-one
left = one
ans = (right-1)//(K-1) + 1
ans += (left-1)//(K-1) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
n = A.index(min(A))
n2 = N-1-n
a,b = divmod(n,2)
c,d = divmod(n2,2)
if b == d == 0:
    print(a+c)
else:
    print(a+c+1)

Submission status: Wrong Answer

Solution code:
# n = int(input())
N, K = map(int, input().split())
A = list(map(int, input().split()))
# d = [list(map(int, input().split())) for _ in range(n)]
# s = input()

if N%(K-1):
    ans = N//(K-1)+1
else:
    ans = N // (K - 1)


print(ans)

Submission status: Wrong Answer

Solution code:
import math
k=int(input().split()[1])-1
s=input().split()
l=[int(item) for item in s]
ind=l.index(1)
p,q=ind,len(l)-ind-1
print(math.ceil(p/k)+math.ceil(q/k))

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
As = list(map(int,input().split()))
ind = As.index(1)
ans = 0
if k >= n:
    print(1)
    quit()
if ind % (k-1):
    ans += ind // (k-1) + 1
else:
    ans += ind // (k-1)
if (n-ind-1) % (k-1):
    ans += (n-ind-1) // (k-1) + 1
else:
    ans += (n-ind-1) // (k-1)
print(ans)

Submission status: Wrong Answer

Solution code:
#! -*- coding: utf-8 -*-

n,k = map(int,raw_input().split())

a = map(int,raw_input().split())

for i in range(n):
    if a[i] == 1:
        break

x = i/(k-1)
if i%(k-1) > 0:
    x += 1
y = (n-i-1)/(k-1)
if (n-i-1)%(k-1) > 0:
    y += 1

print x + y

Submission status: Wrong Answer

Solution code:
data = input().split()
N = int(data[0])
K = int(data[1])

print(int(N / (K - 1)))

Submission status: Wrong Answer

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

cnt = 0
cnt += min_i // (k - 1)
i = min_i + 1
while i < n:
    while a[i] == min_v:
        i += 1
        if i >= n:
            break
    if i >= n:
        break
    cnt += 1
    i += (k - 1)

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

N, K = rdi()
A = rdi()

for i in range(len(A)):
        if A[i] == 1:
                break
assert A[i] == 1

l = i
r = N-i-1

c = (l+K-2) / (K-1) + (r+K-2) / (K-1)
print c

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
j = -1
num = float("inf")
for i in range(n):
    if a[i] < num:
        num = a[i]
        j = i

print((i + 1) // (m - 1) + (n - i - 1) // (m - 1))

Submission status: Wrong Answer

Solution code:
n,k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
x = a.index(1)
print(max(0,(x-1)//(k-1)+1)+max(0,(n-x-2)//(k-1)+1))

Submission status: Wrong Answer

Solution code:
import math
n, k = map(int, input().strip().split())
a = input()
print(math.ceil(n/k))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import math

def main():
    n, k = map(int, input().split())
    an = list(map(int, input().split()))
    assert len(an) == n
    print(math.ceil((n - 1) / 2))

main()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
a = list(map(int,input().split()))
idx = a.index(1)
ans = idx//(K-1) + (N-1-idx)//(K-1)
if idx%(K-1) != 0:
    ans+=1
if (N-1-idx)%(K-1) !=0:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
# your code goes here
buf = input().split()
n = int(buf[0])
k = int(buf[1])
astr = input().split()
#print(n, k, astr)
print(n//k+1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return map(int, input().split())

N, K = inpl()
A = list(inpl())
i = A.index(1)

x = i // (K-1)
y = (N-1) // (K-1)
print(x+y)

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
a=list(map(int, input().split()))
for i in range(n):
    if a[i]==1:
        mi=i
x=n-(mi+1)#最小値から右側
y=mi#最小値から左側
if x%(k-1)==0:
    ax=x//(k-1)
else:
    ax=x//(k-1)+1
if y%(k-1)==0:
    ay=y//(k-1)
else:
    ay=y//(k-1)+1
print(ax+ay)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
min_idx = A.index(1)
ans = min_idx // (K - 1) + (N - min_idx - 1) // (K - 1)
if min_idx % (K - 1) != 0:
    ans += 1
if (N - min_idx - 1) % (K - 1) != 0:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


N, K = readmap()
A = readlist()
ind1 = A.index(1)

print(int(math.ceil(ind1 / (K - 1))) + int(math.ceil((N - 1 - ind1) / (K - 1))))

Submission status: Wrong Answer

Solution code:
import numpy as np


def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def main():
    N, K = lii()
    a = lii()
    min_ix = None
    for i, v in enumerate(a):
        if v == 1:
            min_ix = i
            break

    def t(n, k):
        ans = n // k
        if n % k:
            ans += 1
        return ans

    return t(min_ix, K-1) + t(N-1 - min_ix, K-1)


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout

n, k = map(int, stdin.readline().split())
values = list(map(int, stdin.readline().split()))
ind = values.index(1)

ans = (ind + k - 2) // (k - 1) + (n - 1 - ind + k - 2) // (k - 1)
stdout.write(str(ans))

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
As = list(map(int,input().split()))
ind = As.index(1)
ans = 0
if ind % (k-1):
    ans += ind // (k-1) + 1
else:
    ans += ind // (k-1)
if (n-ind-1) % (k-1):
    ans += (n-ind-1) // (k-1) + 1
else:
    ans += (n-ind-1) // (k-1)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
i = 0
for i, a in enumerate(map(int, input().split())):
    if a == 1:
        break

print((i - 1) // (k - 1) + 1 + (n - i - 1) // (k - 1) + 1)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
print(N//(K-1))

Submission status: Time Limit Exceeded

Solution code:
import math

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

    min_ind = a.index(min(a))

    start = [min_ind - x for x in range(k) if min_ind - x >= 0]
    end = [s+k-1 for s in start]

    se = [(s, e) for s, e in zip(start, end)]
    ans = 10**6
    for s, e in se:
        ans = min(ans, math.ceil(len(a[:s])/(k-1)) + math.ceil(len(a[e+1:])/(k-1)))

    print(ans+1)

main()

Submission status: Time Limit Exceeded

Solution code:
import math

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

    min_ind = a.index(min(a))

    start = [min_ind - x for x in range(k) if min_ind - x >= 0]
    end = [s+k-1 for s in start]

    ans = 10**6
    for s, e in zip(start, end):
        ans = min(ans, math.ceil(len(a[:s])/(k-1)) + math.ceil(len(a[e+1:])/(k-1)))

    print(ans+1)

main()

Submission status: Time Limit Exceeded

Solution code:
import math

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

    min_ind = a.index(min(a))

    start = sorted([min_ind - x for x in range(k) if min_ind - x >= 0])
    end = [s+k-1 for s in start]

    ans = 10**6
    for s, e in zip(start, end):
        ans = min(ans, math.ceil(len(a[:s])/(k-1)) + math.ceil(len(a[e+1:])/(k-1)))

    print(ans+1)

main()

Submission status: Time Limit Exceeded

Solution code:
import math

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

min_ind = a.index(min(a))

start = sorted([min_ind - x for x in range(k) if min_ind - x >= 0])
end = [s+k-1 for s in start]

ans = 10**6
for s, e in zip(start, end):
    ans = min(ans, math.ceil(len(a[:s])/(k-1)) + math.ceil(len(a[e+1:])/(k-1)))

print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
import math

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

min_ind = a.index(min(a))

start = sorted([min_ind - x for x in range(k) if min_ind - x >= 0])
end = [s+k-1 for s in start]

ans = 10**6
for s, e in zip(start, end):
    ans = min(ans, math.ceil(len(a[:s])/(k-1)) + math.ceil(len(a[e+1:])/(k-1)))

print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

# A = [-a for a in A]
# print(A)
heapq.heapify(A)
# A.sort()

count = 0
while sum(A) != A[0] * len(A):
    count += 1
    min_pop = float('inf')
    for i in range(K):
        if A:
            pop = heapq.heappop(A)
            min_pop = min(min_pop, pop)
    heapq.heappush(A, min_pop)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A  = list(map(int,input().split()))
l,r=0,0
ans = 0
for i in range(N):
    if A[i] == min(A):
        ans += len(A[l:i])
        l = i+1
if A[-1] != min(A):
    ans += len(A[l:])
print(ans//(K-1) if ans%(K-1)==0 else ans//(K-1)+1)

Submission status: Time Limit Exceeded

Solution code:
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
k = int(arr_data[0][1])

arr = [int(x) for x in arr_data[1]]
mindata = min(arr)
arr_replace = [mindata for x in range(k)]

cnt = 0
idx=arr.index([x for x in arr if x !=mindata][0])
#
#print(all(x == mindata for x in arr[idx:]),arr[idx:],idx,arr[idx:idx+k],arr[idx+k-1:idx+k-1+k])
#
#idx=5
#
#print(all(x == mindata for x in arr[idx:]),arr[idx:],idx,arr[idx:idx+k],arr[idx+k-1:idx+k-1+k])


while not (all(x == mindata for x in arr)):
    
    if not(all(x == mindata for x in arr[idx:idx + k])):
        cnt += 1
        arr[idx:idx + k] = arr_replace
    
    if not(all(x == mindata for x in arr[idx + k-1:idx + k-1 + k])):
        cnt += 1
        arr[idx + k-1:idx + k-1 + k] = arr_replace
    
    idx += k-1 + k-1
    
#    print(idx,arr)
#    print(arr[idx+1:])
#    print([x for x in arr[idx+1:] if x !=mindata])
#    print(len([x for x in arr[idx+1:] if x !=mindata]))
    
#    print(cnt)
#    if len([x for x in arr[idx+1:] if x !=mindata])!=0:
#        
#        idx=arr.index([x for x in arr[idx+1:] if x !=mindata][0])-1
#        
#    else:
#        break
#    
#    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
k = int(arr_data[0][1])

arr = [int(x) for x in arr_data[1]]
mindata = min(arr)
arr_replace = [mindata for x in range(k)]

cnt = 0
idx=arr.index([x for x in arr if x !=mindata][0])

while not (all(x == mindata for x in arr)):
    
    if not(all(x == mindata for x in arr[idx:idx + k])):
        cnt += 1
        arr[idx:idx + k] = arr_replace
    
    if not(all(x == mindata for x in arr[idx + k-1:idx + k-1 + k])):
        cnt += 1
        arr[idx + k-1:idx + k-1 + k] = arr_replace
    
#    idx += k-1 + k-1
#    print(arr[idx+1:])
#    print([x for x in arr[idx+1:] if x !=mindata])
#    print(len([x for x in arr[idx+1:] if x !=mindata]))
    
#    print(cnt)
    if len([x for x in arr[idx+1:] if x !=mindata])!=0:
        
        idx=arr.index([x for x in arr[idx+1:] if x !=mindata][0])-1
        
    else:
        break
    
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
k = int(arr_data[0][1])

arr = [int(x) for x in arr_data[1]]
mindata = min(arr)
arr_replace = [mindata for x in range(k)]


cnt = 0
idx=arr.index([x for x in arr if x !=mindata][0])

while not (all(x == mindata for x in arr)):
    
    if not(all(x == mindata for x in arr[idx:idx + k])):
        cnt += 1
        arr[idx:idx + k] = arr_replace
    
    if not(all(x == mindata for x in arr[idx + k-1:idx + k-1 + k])):
        cnt += 1
        arr[idx + k-1:idx + k-1 + k] = arr_replace
    
    idx += k-1 + k-1
    
#    print(arr,idx)
#    print(arr[idx:idx+k])
#    print(arr[idx+k-1:idx+k-1+k])
    
print(cnt)