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: Accepted

Solution code:
#!/usr/bin/env python3
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
min_a = min(a)
ans = 0
l = 0
while l < n:
    if a[l] == min_a:
        l += 1
    else:
        if min_a in a[l : l + k - 1]:
            l += k
        else:
            l += k - 1
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from math import ceil

N, K = tuple(map(int, input().split()))
A = np.array([int(x) for x in input().split()])

I = np.argmin(A)
D = max(1, min(N - I, I) - 1)
C = K - 1
small_part = ceil(D / C)
done = C * small_part + 1

print(small_part + ceil((N - done) / C))

Submission status: Accepted

Solution code:
def main():
  t = input().split(" ")
  N, K = int(t[0]), int(t[1])
  
  t = input()
  
  a = (N-2) // (K-1) + 1
  print(a)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

l1 = sys.stdin.readline().strip().split()
l2 = sys.stdin.readline().strip().split()
l1 = [int(x.strip()) for x in l1]
l2 = [int(x.strip()) for x in l2]


N = l1[0]
k = l1[1]
A = l2

p = A.index(1)

nl = [0,0]
nr = [0,0]

def culc(q):
	m = 0
	l = 0
	if k >= q:
		m = 0
	else:
		m = (q-1) // (k-1)
	if m == 0:
		l = 0 #あとの計算の上で、これを端点としても問題ない
	else:
		l = (k-1)*(m-1) + k-1 #indexなので左端は0
	return [m, l]

nl = culc(p)
nr = culc(N-1-p)

#print(nr)
nr[1] = N-1-nr[1]
#print(nl)
#print(nr)

if nl[1] + (k-1) >= nr[1]:
	c = nl[0] + nr[0] + 1
else:
	c = nl[0] + nr[0] + 2

print(c)

Submission status: Accepted

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


import math


ans = math.ceil((N-K) / (K - 1)) + 1
print(ans)

Submission status: Accepted

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

cnt=1
if n <= k:
    
    print(cnt)
    
else:
    
    chkflg = True
    
    while chkflg:
        
        cnt+=1

        s = k + 1 + (k-1) * (cnt-2)
        e = k * 2-1 + (k-1) * (cnt-2)
        
        if s<=n<=e:
            
            chkflg=False
            
            
    print(cnt)

Submission status: Accepted

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



ans = -(-(n-1)//(k-1))

print(ans)

Submission status: Accepted

Solution code:
from bisect import *

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

def reads():
  return [int(x) for x in input().split()]

N, K = reads()
# reads()
print((N-1+K-2)//(K-1))

Submission status: Accepted

Solution code:

N,K = map(int,raw_input().split())
A = map(int, raw_input().split())

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

Submission status: Accepted

Solution code:
#coding: UTF-8

NK = list(map(int, input().split()))
A = list(map(int, input().split()))

N,K = NK[0],NK[1]

wb = True
counter = 0


while wb:
    if counter == 0:
        N = N - K
    else:
        N = N - (K - 1)
    counter+=1
    if N <= 0:
        wb = False

print(counter)

Submission status: Accepted

Solution code:
import math
n, k = [int(i) for i in input().split()]
A = [int(i) for i in input().split(" ")]

print(math.ceil((n-1)/(k-1)))


# keep element as middle or end
# if you have 9 elements, then length is 2

Submission status: Accepted

Solution code:
import math

if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    #A = np.array(list(map(int, input().split())))
    input()
    ans = math.ceil((N-1) / (K-1))
    print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
print((n - 2) // (k - 1) + 1)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
n = 0
i = 0
first = True
while True:
    if first:
        n += K
    else:
        n += K - 1
    first = False
    i += 1
    if n >= N:
        break
print(i)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
print( ( (n-1 + k-2)//(k-1) ) )

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

assert isinstance(A,list)
a = A.index(1)

print(math.ceil((N-1)/(K-1)))

Submission status: Accepted

Solution code:
import sys

n, k = map(int, sys.stdin.readline().split())

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

Submission status: Accepted

Solution code:
import sys, math

n, k = map(int, sys.stdin.readline().split())

print(math.ceil((n-1) / (k-1)))

Submission status: Accepted

Solution code:
n,k=map(int,input().split(' '))
print((n+k-3)//(k-1))

Submission status: Accepted

Solution code:
I=raw_input()
IL=I.split()
n=int(IL[0])
k=int(IL[1])
I2=raw_input()
x=(n-1)/(k-1)
if(x*(k-1)!=(n-1)):
   x+=1
print x

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil

N, K = [int(w) for w in input().split()]
A    = [int(w) for w in input().split()]
if len(A) != N: raise

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
width=K
answer=1

while(True):
 if width>=N:
  break;
 width+=K-1
 answer+=1

print(answer)

Submission status: Accepted

Solution code:
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = n
for i in range(0,k-1):
    ans = min((math.ceil((n-1-i)/(k-1)) + math.ceil(i/(k-1))),ans)
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, raw_input().split())
A = map(int, raw_input().split())
print (N-2)/(K-1)+1

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
i = a.index(min(a))
def solve(x, y):
    q1 = (x+k-2)//(k-1)
    r = ((k-1)-x%(k-1))%(k-1)
    q2 = max(0, y+k-2-r)//(k-1)
    return q1+q2
x = i
y = n-i-1
print(min(solve(x, y), solve(y, x)))

Submission status: Accepted

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

print((N-1+K-2)//(K-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n,k = input().split()
n,k = int(n),int(k)

if (n-1)%(k-1)==0:
    print((n-1)//(k-1))
else:
    print((n-1)//(k-1)+1)

Submission status: Accepted

Solution code:
from math import ceil

N, K = map(int, input().split())
A = [int(_) for _ in input().split()]
front = A.index(1)
back = N - front - 1

ret = 10000000
for i in range(K):
    ff = front - i
    bb = back - (K - 1 - i)
    if ff >= 0 and bb >= 0:
        ret = min(ret, 1 + ceil(ff/(K-1)) + ceil(bb/(K-1)))
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N, K = [int(i) for i in input().split()]
a = list(map(int, input().split()))
 
pos = a.index(1)
 
ans = math.ceil((N-1)/(K-1))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
print(math.ceil((N-K)/(K-1))+1)

Submission status: Accepted

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

print(math.ceil((N-1)/(K-1)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

a=[int(i) for i in input().split()]

l=(n-1)/(k-1)

m=math.ceil(l)

print(m)

Submission status: Accepted

Solution code:
import math
s=input().split()
n,k=int(s[0])-1,int(s[1])-1
print(math.ceil(n/k))

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    V = K-1
    ans += d // V
    if d % V != 0:
      ans += 1
  e = N-1-c
  if e != 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans += 1
  ans1 = 0
  ans2 = 0
  if d <= K-1:
    ans1 += 1
    ex = e -(K-d-1)
    if ex >= 0:
      V = K-1
      ans1 += ex // V
      if ex % V != 0:
        ans1 += 1
  else:
    ans1 = 999999999999999999999999999999
  if e <= K-1:
    ans2 += 1
    dx = d -(K-e-1)
    if dx >= 0:
      V = K-1
      ans2 += dx // V
      if dx % V != 0:
        ans2 += 1
  else:
    ans2 = 999999999999999999999999999999
  ans3 = 0
  ans4 = 999999999999999999
  V = K-1
  for i in range(K):
    ans3 = 0
    dx = d- i
    ex = e - (K - i - 1)
    ans3 += 1
    if dx > 0:
      if ex > 0:
        ans3 += ex//V
        if ex % V != 0:
          ans3 += 1
        ans3 += dx//V
        if dx % V != 0:
          ans3 += 1
        ans4 = min(ans4,ans3)
  print(min(ans,ans1,ans2,ans4))

Submission status: Accepted

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

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

input_line = input()
array_str = input_line.split()

array = list(map(int, array_str))

for index, number in enumerate(array):
    if number == 1:
        index_min = index
        break

# from forward

equalized = 1
i = 1
while equalized < num_array:
    equalized += (num_equal - 1)
    # print(i, equalized)
    i += 1

print(i - 1)

Submission status: Accepted

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

Submission status: Accepted

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

while N > K:
   N = N - K + 1
   count += 1

print(count + 1)

Submission status: Accepted

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)

f_mod = ((k-1) - former % (k-1)) % (k-1)
l_mod = ((k-1) - later % (k-1)) % (k-1)


count = former_c + later_c

if f_mod + l_mod >= k - 1:
    count -= 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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 and migii == 0:
    #    mini = 0
    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: Accepted

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] - 1)
 
if (a[0] - 1) % (a[1] - 1) != 0:
	k += 1


print(k)

Submission status: Accepted

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

Submission status: Accepted

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((n - 2) // (k - 1) + 1)
	else:
		print(min((one_index - 1) // (k - 1) + (n - one_index - 2) // (k - 1) + 2, (n - 2) // (k - 1) + 1))

Submission status: Accepted

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

print ((n-1) / (k-1) + ((n-1) % (k-1) != 0))

Submission status: Accepted

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)
    ans = min(ans, cnt(N - 1, K))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
pos_1 = A.index(1)
former = pos_1
latter = N - 1 - pos_1
ans = 0
s = min(former, latter)
l = max(former, latter)
if N == K:
  ans = 1
else:
  ans += s // (K-1)
  if s % (K-1) != 0:
    ans += 1
    l -= K - s % (K -1) - 1
  ans += l // (K-1)
  if l % (K-1) != 0:
    ans += 1
print(ans)

Submission status: Accepted

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


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


if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    i = A.index(1)

    # print(kiriage(i, K-1) + kiriage(N-i-1, K-1))
    l = i // (K-1)
    r = (N-i-1) // (K-1)

    rest_left = i - l*(K-1)
    rest_right = (N-i-1) - r*(K-1)
    rest = N - (l+r) * (K-1)


    if rest_left == 0 and rest_right == 0:
        print(l+r)
    elif rest_left == 0 or rest_right == 0:
        print(l+r+1)
    elif rest <= K:
        print(l + r + 1)
    else:
        print(l+r+2)

Submission status: Accepted

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 + 1, 0), i1 + 1):
    ans = min(ans, (i + k - 2) // (k - 1) + (n - i - 2) // (k - 1) + 1)

print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
src = list(map(int,input().split()))
ans = 1
n = K
while n < N:
    n += (K-1)
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    l = A[:i]
    r = A[i+1:]
    ans = math.ceil((len(l)+len(r)) / (K-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: Accepted

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()

#c = (N+K-3) / (K-1)
x = (N-1) / (K-1)
y = (N-1) % (K-1)
if y:
        x += 1

print x

Submission status: Accepted

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,K-1)
c,d = divmod(n2,K-1)
if b == d == 0:
    print(a+c)
elif b+d < K:
    print(a+c+1)
else:
    print(a+c+2)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
min = 100001
d = 0
for i in range(n):
	if a[i]<min:
		min=a[i]
		d = n

b = int((n-1)/(k-1))
if (n-1)%(k-1) != 0:
	b += 1

print(b)

Submission status: Accepted

Solution code:
N, K = [int(a) for a in input().split()]
ans = (N-1) // (K-1) + ((N-1) % (K-1)> 0)
print(str(ans))

Submission status: Accepted

Solution code:
def inpl(): return map(int, input().split())

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

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

Submission status: Accepted

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

if n == k:
  print("1")
  exit()

b = min(a)

i = 0
result = 0
while i < n:
  if a[i] == b:
    i += 1
    continue
  result += 1
  hoge = i + k
  if i + k > n:
    break
  if min(a[i:hoge]) == b:
    i += k
  else:
    i += k - 1

print(result)

Submission status: Accepted

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

print(math.ceil((n-1)/(k-1)))

Submission status: Accepted

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

Submission status: Accepted

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, 0

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

    if N-1 - min_ix >= K-1 and min_ix >= K-1:
        ans1, p1 = t(min_ix, K-1)
        ans2, p2 = t(N-1 - min_ix, K-1)
        ans = ans1 + ans2
        if p1 > 0 and p2 > 0 and p1 + p2 <= K-1:
            ans -= 1
        return ans

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

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


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

Submission status: Accepted

Solution code:
import math

N,K=map(int, raw_input().split())
A=map(int, raw_input().split())
i=A.index(1)

ans=99999999
for k in range(K):
    tmp=1
    kk=(K-1)-k
    lefti=max(0, i-k)
    righti=min(N-1, i+kk)
    left= int(math.ceil((lefti)/float(K-1)))
    right= int(math.ceil((N-righti-1)/float(K-1)))
    ans=min(ans, tmp+left+right)
print ans

Submission status: Accepted

Solution code:
import math

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

pos = a.index(1)

# 基本は左からつめる
cnt_base = math.ceil( ( n-k ) / (k-1) ) + 1

print(cnt_base)

Submission status: Accepted

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((N-K)/(K-1))+1)

Submission status: Accepted

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

Submission status: Accepted

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

if n == k:
    print(1)
else:
    i = 0
    for i, a in enumerate(map(int, input().split())):
        if a == 1:
            break
    left = (i - 1) // (k - 1) + 1
    lr = (k - 1) * left + 1
    print(left + (n - lr - 1) // (k - 1) + 1)

Submission status: Accepted

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

start = a.index(1) + 1
left = (start - 1) // (k - 1) + 1
new_start = (k - 1) * left + 1
right = (n - new_start - 1) // (k - 1) + 1
count = left + right
print(count)

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]

counter = 0
idx = 1
while idx < n:
    idx -= 1
    counter += 1
    idx += k
    
print(counter)

Submission status: Accepted

Solution code:
import numpy as np

def solve(N, K, As):
    return int(np.ceil((N-1) / (K-1)))

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

Submission status: Accepted

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((N - 1) / (K - 1)))

Submission status: Accepted

Solution code:
import math
def find_min(length, window_size):
    return math.ceil((length-window_size)/(window_size-1)) + 1

args = input().split(" ")
length = int(args[0])
window_size = int(args[1].rstrip())
array = input().split(" ")

print(find_min(length, window_size))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import math
ans = 0
if len(a)<=k:
  ans = 1
else:
  ans+=1+math.ceil((len(a)-k)/(k-1))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
k = i
while k > 0:
    k = max(0, k - m + 1)
    ans += 1

l = i
while l < n - 1:
    l = min(n - 1, l + (m - 1))
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math

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

A_np = np.array(A)

argmin = A_np.argmin() + 1

left = (math.ceil((argmin - K) / (K - 1)) + 1)
left = max(0, left)

already = (left - 1) * (K - 1) + K if left != 0 else 1

nokori = (N - already + 1)

right = (math.ceil((nokori - K) / (K - 1)) + 1)

print(right + left)

Submission status: Accepted

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
    mi = min(an)
    imin = []
    for i in range(n):
        if an[i] == mi:
            imin.append(i)

    print(math.ceil((n - 1) / (k - 1)))

main()

Submission status: Accepted

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

l = 1
ans = 0

while l < n:
    ans += 1
    l += k-1

print(ans)

Submission status: Accepted

Solution code:
from math import ceil

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

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

Submission status: Accepted

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
    flag = False
    for j in range(k - 1):
        if not i + j < n:
            break
        if a[i+j] == b:
            flag = True
        a[i+j] = b
    if flag and i+k-1 < len(a):
        a[i+k-1] = b
    ret += 1

print(ret)

Submission status: Accepted

Solution code:
# encoding:utf-8

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

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

if __name__ == '__main__':
	main()

Submission status: Accepted

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
#

ans = (n-1)/(k-1)
if (n-1)%(k-1)>0:
    ans += 1

print ans

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(1, 100000):
    if N <= K + max(0, (K - 1) * (i - 1)):
        print(i)
        break

Submission status: Accepted

Solution code:
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('a1.in')


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


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


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n, k = read_int_list()
    a = read_int_list()
    res = 1
    for i in range(k - 1, n - 1, k - 1):
        res += 1
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
N, K = map(int, sys.stdin.readline().split())
rhs = N - K
ans = rhs // (K - 1) + 1
while (K - 1) * (ans - 1) < rhs:
    ans += 1
print(ans)

Submission status: Accepted

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 - i
while(i < n - 1):
    count += 1
    i += (k - 1)

print(count)

Submission status: Accepted

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)

ans = 100000
for k in range(max(0, ind1 - K + 1), ind1 + 1):
    left = int(math.ceil(k / (K - 1)))
    right = max(0, int(math.ceil((N - k - K) / (K - 1))))
    ans = min(ans, left + right + 1)

print(ans)

Submission status: Accepted

Solution code:
import math

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

ans = 1 + int(math.ceil((n - k) / (k - 1)))

print(ans)

Submission status: Accepted

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

count = 0
now = 0
while now < n-1:
	now += k-1
	count += 1
	if now == s and (now+k) > n-1:
		now += k-2
		count += 1
print(count)

Submission status: Accepted

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

ans = (N-1)//(K-1)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
read = lambda: map(int, input().split())
n, k = read()
a = list(read())
x = a.index(1)
ans = (n - 2) // (k - 1) + 1
print(ans)

Submission status: Accepted

Solution code:
n, k = (int(x) for x in input().split())
perm = [int(x) for x in input().split()]

times = (n - 1 + k - 2) // (k - 1)
print(times)

Submission status: Accepted

Solution code:
import math
N,K = [int(x) for x in input().split()]
print(math.ceil((N-1)/(K-1)))

Submission status: Accepted

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

Submission status: Accepted

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-2) // (k - 1)
i = max(min_i + 1, (min_i+ k-2) // (k - 1) * (k - 1) + 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: Accepted

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

Submission status: Accepted

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-1)%(K-1):
    ans =(N-1)//(K-1)+1
else:
    ans = (N-1) // (K - 1)


print(ans)


# K = int(input())

Submission status: Accepted

Solution code:

import math

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

ans = 1 + int(math.ceil((n - k) / (k - 1)))

print(ans)

Submission status: Accepted

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)

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
a = len(input().split())
func = lambda x: int(x) if x == int(x) else int(x) + 1
print(func((a - 1) / (K - 1)))

Submission status: Accepted

Solution code:
INF = 10 ** 20

n, k = map(int, input().split())
alst = list(map(int, input().split()))
init_ind = alst.index(1)
left = init_ind
right = n - init_ind - 1

ans = INF
for l in range(k):
  r = k - l - 1
  if l <= init_ind and init_ind + r <= n - 1:
    left2 = left - l
    right2 = right - r
    ans = min(ans, 1 + left2 // (k - 1) + bool(left2 % (k - 1)) + right2 // (k - 1) + bool(right2 % (k - 1)))
print(ans)