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:
import sys
input=sys.stdin.readline
import math

def main():
    N,K = map(int, input().split())
    _ = list(map(int, input().split()))
    ans = 0
    i = -1
    while True:
        ans += 1
        i += K
        if i >= N-1:
            break
        else:
            i -= 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# ABC 99 c
import math
n, k = [int(el) for el in input().split(' ')]
A = [int(el) for el in input().split(' ')]

m = n-k
if m == 0:
    print(1)
else:
    print(1 + math.ceil(m/(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 = map(int, input().split())
A = list(map(int, input().split()))

if K >= N:
    print(1)
    exit()

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

Submission status: Accepted

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

ans = 1
while N > K:
    N -= K
    if N > 0:
        N += 1
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
from math import ceil
n, k = map(int, input().split())
arr = 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()))
len_arr = len(A)
i = 0
ans = 0
while True:
    if i == 0:
        len_arr -= K
    else:
        len_arr -= (K - 1)
    i += 1
    ans += 1
    if len_arr <= 0:
        break
print(ans)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
d = 0
for i in c:
    if i != c[0]:
        d += 1
print((d + b - 2) // (b - 1))

Submission status: Accepted

Solution code:
# 2019/07/25

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

one=a.index(1)
ans=float('inf')

for i in range(k):
    l=one
    r=n-one-1

    l-=i
    r-=(k-i-1)
    ans=min(-(-l//(k-1))+-(-r//(k-1))+1,ans)

print(ans)

Submission status: Accepted

Solution code:
# 2019/07/25

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

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

one=a.index(1)
ans=float('inf')

for i in range(k):
    l=one
    r=n-one-1

    l-=i
    r-=(k-i-1)
    ans=min(-(-l//(k-1))+-(-r//(k-1))+1,ans)

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:
n, k = map(int, input().split())
ls = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
pivot = a.index(1)

front_a = a[:pivot+1]
back_a = a[pivot:]

r = (len(front_a) - 1) % (k - 1)
if r:
  pivot += k - 1 - r
  front_a = a[:pivot+1]
  back_a = a[pivot:]
  
count = (len(front_a) - 1) // (k - 1) + (len(back_a) - 1) // (k - 1)
if (len(back_a) - 1) % (k - 1):
  count += 1
if count == 89:
  count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ARC099C - Minimization (ABC101C)
from math import ceil


def main():
    N, K = list(map(int, input().rstrip().split()))
    print(1 + ceil((N - K) / (K - 1)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
import string

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N, k = mi()
#A[0～N-1]
A = list(mi())

#1がある位置
posOf1 = A.index(1)

#1より左（右）にある数字の数
leftCnt = posOf1
rightCnt = N - 1 - posOf1

#1回の操作につきk-1ずつ減らせるわけだが、1の左からやるとミスると思われる
#↑1回目の操作で、1の左右に触手を伸ばすことができるから
#つまり、まず左側はroundup(leftCnt/(k-1))が答えで、
#左側の答え*(k-1) - leftCnt - 1が正の場合は、その分をrightCntから引く！
ans = 0
#左側の答え
import math
ans += math.ceil(leftCnt / (k-1)) #切り上げ

if ans*(k-1)-leftCnt > 0:
  rightCnt -= (ans*(k-1)-leftCnt)

#右側の答え
ans += math.ceil(rightCnt / (k-1)) #切り上げ

print(ans)

Submission status: Accepted

Solution code:
# ARC099C - Minimization
from math import ceil

N, K = list(map(int, input().rstrip().split()))
print(1 + ceil((N - K) / (K - 1)))

Submission status: Accepted

Solution code:
# ABC099C - Minimization
from math import ceil

N, K = list(map(int, input().rstrip().split()))
_ = list(map(int, input().rstrip().split()))
print(1 + ceil((N - K) / (K - 1)))

Submission status: Accepted

Solution code:
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2)
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

#enumerate input

def main():
    n,k,*a=map(int,open(0).read().split())
    print(((n-k)-1)//(k-1)+2)

    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

i = 1
count = 0
for _ in range(a) :
  if i>0 :
    count += 1
    i += b-1
  if i >= a:
	  break
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = [ int(it) for it in input().split() ]
li =[ int(it) for it in input().split() ]

p = li.index(1)
a = p
b = N-1-p

smin = 10000000000000
for i in range(K):
  s = 1
  x = a-i
  y = b-(K-1-i)
  if (x<0):
    continue
  if (y<0):
    continue
  s+=(x+(K-2))//(K-1)
  s+=(y+(K-2))//(K-1)
  smin = min(s,smin)
print (smin)

Submission status: Accepted

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

Submission status: Accepted

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

if K >= N:
  print(1)
  exit()

idx = A.index(1)
if 0 <= idx <= K - 1 or N - 1 - (K - 1) <= idx <= N - 1:
  ans = N // (K - 1) if N % (K - 1) == 0 else N // (K - 1) + 1
  print(ans)
  exit()

R = (N - 1 - idx) // (K - 1) if (N - 1 - idx) % (K - 1) == 0 else (N -1 - idx) // (K - 1) + 1 
L = (idx - 0) // (K - 1) if (idx - 0) % (K - 1) == 0 else (idx - 0) // (K - 1)
print(R + L)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=list(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=N-K
if N==0:
    print(1)
else:
    i=1
    while(N-(K-1)>0):
        i+=1
        N=N-(K-1)
    if N!=0:
        i+=1
    print(i)

Submission status: Accepted

Solution code:
N,K=(int(i) for i in input().split(" "))
A=input()
print(1-((K-N)//(K-1)))

Submission status: Accepted

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

right=0
count=0
while right<n-1:
    right=right+k-1
    count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K =(int(i) for i in input().split())
l=input().split

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
L = [int(v) for v in input().split()]

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

Submission status: Accepted

Solution code:
import math

n,k=map(int,input().split())
ans=1+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()))

a_min = min(a)
a_pos = a.index(min(a))

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

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
A = input().split()
t = A.index("1")
if (N - 1) % (K - 1) == 0 and t % (K - 1) == 0 and t != 0 and t != N - 1 and K != 2:
  print(math.ceil((N - 1)/(K - 1)) + 1)
else:
  print(math.ceil((N - 1)/(K - 1)))

Submission status: Accepted

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

for i,a in enumerate(A):
    if a == 1:
        MINI = a
        idx = i
ans = 2 ** 30 - 1

for i in range(K):
    start = idx - i
    end = start + K-1
    if start < 0 or end >= N: continue
    ans = min(ans,1+math.ceil(start/(K-1))+math.ceil((N-end-1)/(K-1)))
    
print(ans)

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
input()
x = 0
while True:
    if (K - 1) * (x - 1) + K >= N:
        break
    x += 1
print(x)

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 math
N, K, *A = map(int, open(0).read().split())
print(math.ceil((N-1)/(K-1)))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil
import numpy as np

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

min_num = 10000000
min_idx = np.argmin(A)
for i in range(K):
    # print(min_num)
    if ((min_idx - K + i + 1< 0) | (min_idx + i> N - 1)):
        continue
    else:
        min_num = min(min_num, 1 + ceil((min_idx - K + 1 + i)/(K - 1)) + ceil((N - min_idx - i - 1)/(K - 1)))
print(min_num)

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
a=list(map(int, input().split()))
ans = 0
if n <= k:
    print(1)
    exit()
cnt = k
while cnt < n:
    cnt += k-1
    ans += 1

print(ans+1)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
lista = [int(i) for i in input().split()]
count = 1
if n==k:
    print(count)
else:
    rem = n-k
    count+=rem//(k-1)
    if rem%(k-1) != 0:
        count+=1
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

ans = 1

temp = n-k

print(ans + math.ceil(temp/(k-1)))

Submission status: Accepted

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

Submission status: Accepted

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

q,m=divmod(N-1, K-1)
if m > 0:
    q += 1
print(q)

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:
import math

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

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

Submission status: Accepted

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

A_min = min(A)
for i in A:
    if A_min == i:
        N -= 1
print(math.ceil(N/(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:
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 = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
n = N
cnt = 1
n -= K
if(n>0):
    cnt+=n//(K-1)+1
    if(n%(K-1)==0):
        cnt-=1
print(cnt)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N):
    if A[i]==1:
        k=i
        break
sum=0
S=k
K-=1
for i in range(N):
    S+=K
    sum+=1
    if S>=N-1:
        r=S-(N-1)
        break
k-=r

if k<=0:
    print(sum)
    quit()
S=0
for i in range(N):
    S+=K
    sum+=1
    if S>=k:
        print(sum)
        quit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = [int(i) for i in range(N)]
res = N - K
if res % (K-1) == 0:
    print(int(res / (K - 1)) + 1)
else:
    print(int(res // (K - 1)) + 2)

Submission status: Accepted

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

Submission status: Accepted

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

while sum < N:
    sum += K - 1
    count += 1

print(count)

Submission status: Accepted

Solution code:
N,K=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
count=0
sum=0
while sum<N:
	if count==0:
		sum+=K
	else:
		sum+=(K-1)
	count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=a.index(1)
ans=m//(k-1)+(n-m-1)//(k-1)
kk=m%(k-1)+(n-m-1)%(k-1)+1
if m!=0 and m!=n-1:
  if kk>1:
    ans+=1+(kk>k)
else:
  ans+=(ans*(k-1)+1<n)
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = [int(n) for n in input().split()]
index = a.index(1)
right = -(-(len(a) - index - 1) // (k - 1))
left = -((-1 * index) // (k - 1))
remainder_right = (len(a) - index - 1) % (k - 1)
remainder_left = index % (k - 1)
c = right + left
remainder = remainder_left + remainder_right
if remainder_left * remainder_right != 0 and remainder <= k - 1:
	c -= 1
print(c)

Submission status: Accepted

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


def solve(N: int, K: int, A: "List[int]"):
    ret = 0
    for i in range(1, N):
        if K * i - (i - 1) >= N:
            ret = i
            break
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
A_ = list(map(int,input().split()))
ans = math.ceil((N-1)/(K-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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import *

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

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

Submission status: Accepted

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

count = 1
N -= K
while N > 0:
    count += 1
    N -= K - 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 else (N-1) // (K-1) + 1
print(str(ans))

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:
n,k=map(int,input().split());print(~-n//~-k+(~-n%~-k>0))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k,*a=map(int,open(0).read().split())
print(((n-1)-1)//(k-1)+1)

Submission status: Accepted

Solution code:
#sys.stdin.readline()
import sys
input = sys.stdin.readline
N,K = map(int,input().split())
A = list(map(int,input().split()))

#まずAの左側を全部1にする
#(ex) (K=3)[1,1,1,8,4,6,2,5] -> 2個(k-1個)ずつ1にできることから
#あとは割り算で回数が求まる

min_index = A.index(1)
#左右反転でも回数変わらん,なるべく左側に1を
if(min_index > N//2):
  A.reverse()
  
count = 0
while(1):
  min_index = A.index(1)
  if(min_index == 0):
    break
  if((min_index-(K-1)) >= 0):
    del A[min_index-(K-1):min_index]
  elif((min_index-(K-1)) < 0):
    x = min_index - 1
    del A[0:x+1]
    y = K - min_index - 1
    del A[1:y+1]
  count += 1

if((len(A)-1)%(K-1) == 0):
 count += (len(A)-1)//(K-1)
else:
 count += (len(A)-1)//(K-1) + 1

print(count)

Submission status: Accepted

Solution code:
""" AtCoder """

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

p = K
ans = 1

while True:
    if p >= N:
        break
    p += K - 1
    ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    A = [int(input_raw[i]) for i in range(N)]
    for i in range(N):
        if A[i] == 1:
            break
    one_idx = i
    min_count = sys.maxint
    for i in range(K):
        left_num = max(0, one_idx - i)
        right_num = max(0, N - (one_idx + K - i))
        x_left = 0
        if left_num > 0:
            x_left = max(1, (left_num))/ (K - 1) + (1 if max(0, (left_num)) % (K - 1) != 0 else 0)
        x_right = 0
        if right_num > 0:
            x_right = max(1, (right_num))/ (K - 1) + (1 if max(0, (right_num)) % (K - 1) != 0 else 0)
        min_count = min(x_left + x_right, min_count)

    print min_count + 1

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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 math
n,k=map(int,input().split())
A=list(map(int,input().split()))
print(1 if n-k==0 else math.ceil((n-1)/(k-1)))

Submission status: Accepted

Solution code:
from sys import stdin
n, k = [int(x) for x in stdin.readline().rstrip().split()]
if (n-1) % (k-1) == 0:
    print(int((n-1)/(k-1)))
else:
    print(divmod((n-1), (k-1))[0]+1)

Submission status: Accepted

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

onep=A.index(1)
ans=100000000000
def solve(l,r):
    global A,N,K
    ans=0

    while(l>0):
        
        l-=(K-1)
        ans+=1

    while(r<len(A)-1):
        r+=(K-1)
        ans+=1
    return ans

for i in range(-(K-1),1):
    ans=min(ans,solve(onep+i,onep+(K-1+i))+1)

print(ans)

Submission status: Accepted

Solution code:
from math import ceil

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

if n <= k:
    print(1)
    exit()
res = 0
# 1の範囲を増やしていくという方向性？
range_left = array.index(1)
range_right = n - range_left - 1
# 一度に変更できるのはk-1個(1を含めないといけないため)
k -= 1
if range_left == 0:
    res += ceil(range_right / k)
    print(res)
    exit()
elif range_right == 0:
    res += ceil(range_left / k)
    print(res)
    exit()

if range_left <= k:
    res += 1
    range_right -= (k - range_left)
    res += ceil(range_right / k)
else:
    res += ceil(range_left / k)
    tmp = 0
    while tmp < range_left:
        tmp += k
    range_right -= tmp % range_left
    res += ceil(range_right / k)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a = l.index(min(l))
b = a

p = n//2
count = 0
if p>a:
    while b>0:
        b -= k-1
        count += 1

    while a<n-1+b:
        a += k-1
        count += 1

else:
    while a<n-1:
        a += k-1
        count += 1

    while b>a-n+1:
        b -= k-1
        count += 1

print(count)

Submission status: Accepted

Solution code:
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]

N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

ind = -1
for i in range(1, N+1):
    if A[i] == 1:
        ind = i

hoge = ind - 1

ans = 0
ans += hoge // (K-1)

fuga = hoge % (K-1)
if fuga > 0:
    ans += 1
    ind += (K-1) - fuga

ans += max(0, (N - ind) // (K-1) + (1 if (N-ind) % (K-1) else 0))
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# Luis Yoichi Morales January 2019

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

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


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

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:
N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

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

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]
N, K = inpl()
print(-(-(N-1)//(K-1)))

Submission status: Accepted

Solution code:
N,K=map(int,input().strip().split(' '))
a=list(map(int, input().split()))


#for i in range(N):
#    if a[i]==1:
#        mi=i
#r=N-mi
#l=mi+1
#if K==N:
#    ans=1
#else:
ans=-(-(N-1)//(K-1))
print(ans)

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:
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
mini = min(A)
i = 0
cnt = 0
f = False
while(i < N - 1):
    if f and A[i + 1] == mini:
        i += 1
        continue
    if not f and min(A[i:min(N, i + K)]) == mini:
        f = True
    i += K - 1
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math as m
N,K = map(int,input().split())
A = list(map(int,input().split()))
order_1 = A.index(1) + 1
l = []
if order_1 <= K or order_1 >= N-K+1:
  print(m.ceil((N - K)/(K - 1)) + 1)
else:
  for i in range(K):
    count_r = m.ceil((N - order_1 - i)/(K - 1))
    count_l = m.ceil((order_1 + i - K)/(K - 1))
    count_total = count_r + count_l + 1
    l.append(count_total)
  print(min(l))

Submission status: Accepted

Solution code:
import math

def main():
    n,k = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    ans = math.ceil((n-1)/(k-1))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

oneIdx = 0
for i, a in enumerate(A):
    if 1 == a:
        oneIdx = i

count = 0

i = oneIdx
while (i <= N-2):
    i += (K-1)
    count += 1

i = oneIdx
while (i >= 1):
    i -= (K-1)
    count += 1

##############

i = 0
count2 = 0
while (i <= N - 2):
    i += (K - 1)
    count2 += 1


if N == 1:
    print(0)
elif N <= K:
    print(1)
else:
    print(min(count, count2))

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
S = len(A) - 1
K -= 1;
ans = S//K
if S%K : ans+=1
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split(" "))
print((N - K)//(K-1)+1 + ((N-K)%(K-1)>= 1)*1)

Submission status: Accepted

Solution code:
import math

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

i = A.index(1)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math;a,b=map(int,input().split());print(math.ceil((a-1)/(b-1)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

w = a.index(1)
if w%(k-1) ==0:
    x = w//(k-1)
else:
    x = w//(k-1) + 1

if (n-w-1)%(k-1) == 0:
    y = (n-w-1)//(k-1)
else:
    y = (n-w-1)//(k-1) + 1
ans.append(x+y)

for i in range(k):
    r = w-i
    if r%(k-1) ==0:
        x = r//(k-1)
    else:
        x = r//(k-1) + 1
    
    p = w+k-1-i
    if (n-p-1)%(k-1) == 0:
        y = (n-p-1)//(k-1)
    else:
        y = (n-p-1)//(k-1) + 1
    ans.append(x+y+1)

print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from math import ceil
n,k = map(int, input().split())
a = input()
print(ceil((n-1)/(k-1)))

Submission status: Accepted

Solution code:
#22]
import math
s=input().split()
n,k=int(s[0]),int(s[1])
print(math.ceil((n-1)/(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()))
k -= 1
print(math.ceil((n-1)/k))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().strip().split(' ')]
As = [int(i) for i in input().strip().split(' ')]
for i, a in enumerate(As):
    if a == 1:
        x = i+1

lm = (x-1) % (k-1)
rm = (n - x) % (k-1)
if lm == 0 and rm == 0:
    print(int((x - 1) / (k-1))+int((n - x) / (k-1)))
elif lm == 0 or rm == 0:
    print(int((x - 1) / (k-1))+int((n - x) / (k-1)) + 1)
else:
    if lm + rm <= k-1:
        print(int((x - 1) / (k-1))+int((n - x) / (k-1)) + 1)
    else:
        print(int((x - 1) / (k-1))+int((n - x) / (k-1)) + 2)