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: 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 = 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)

Submission status: Accepted

Solution code:
import math
N,K,*A=map(int,open(0).read().split())

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

Submission status: Accepted

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

while len > 1:
    len = len - k + 1
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A = list(map(int,input().split()))
val_memo = {}
for i in range(N):
    if A[i] in val_memo:
        val_memo[A[i]] += 1
    else:
        val_memo[A[i]] = 1

val_memo = sorted(val_memo.items(), key=lambda x: x[0])
total = N-val_memo[0][1]
if total%(K-1):
    print(total//(K-1)+1)
else:
    print(total//(K-1))

Submission status: Accepted

Solution code:
import collections

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

a = list(map(int, input().split()))
c= collections.Counter(a)

length = n - c.most_common()[0][1] + 1

if length == 1:
    ans = 0
else:
    ans = (length + k - 3) // (k - 1)
    
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
a = inpl()
k -= 1
print((n-1+k-1)//k)

Submission status: Accepted

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

A_min = min(A)
N = n-len([i for i in A if i == A_min])
print(math.ceil(N/(k-1)))

Submission status: Accepted

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = LI()

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
ind = A.index(1)
n = ind//(K-1)
if ind%(K-1):
    n += 1
m = (N-1-ind)//(K-1)
if (N-1-ind)%(K-1):
    m += 1
cmin = n+m
for i in range(max(1,ind+K-N),min(ind,K-1)+1):
    n = (ind-i)//(K-1)
    if (ind-i)%(K-1):
        n += 1
    m = (N-ind-K+i)//(K-1)
    if (N-ind-K+i)%(K-1):
        m += 1
    cnt = n+m+1
    cmin = min(cmin,cnt)
print(cmin)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
a = inpl()
now = 0
res = 0
for x in a:
    if x != 1: now += 1
    if now == k-1:
        res += 1
        now = 0
if now: res += 1
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
_=list(map(int,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 n == k:
  print(1)
else:
  print(-(-(n-1)//(k-1)))

Submission status: Accepted

Solution code:
import math

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

if n <= k:
    print(1)
else:
    print(math.ceil((n-1)/(k-1)))

Submission status: Accepted

Solution code:
from math import ceil

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,K = MI()
A = LI()

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, k = map(int, input().split())
a = list(map(int, input().split()))
one_index = a.index(1)
l_min = max(0, one_index - k + 1)
l_max = one_index

ans = 10 ** 7
for i in range(l_min, l_max + 1):
    r = min(n - 1, i + k - 1)
    l_ans = ((i + (k - 1) - 1) // (k - 1))
    r_ans = ((((n - 1) - r) + (k - 1) - 1) // (k - 1))
    ans = min(ans, l_ans + r_ans + 1)
print(ans)

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

def main():
    n, k = input_list()
    a = input_list()
    b = n - 1
    x = k - 1
    ans = b // x
    if b % x == 0:
        print(ans)
    else:
        print(ans + 1)

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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input():
  return sys.stdin.readline().rstrip()

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

ans=0
right=0
while True:
  if ans==0:
    right+=K
  else:
    right+=K-1
  ans+=1
  if N<=right:
    break;

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, k, *a = map(int, open(0).read().split())
print(0 - - (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:
# coding: utf-8
import math
n, k = map(int,input().split())
A = list(map(int,input().split()))
for i in range(n):
    if A[i]==1:
        cnt=i

l = i
r = n - i - 1
r = max(r - math.ceil(l/(k-1)) * (k-1) + l, 0)
print(math.ceil(l/(k-1)) + math.ceil(r/(k-1)))

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k, *a = map(int, open(0).read().split())
mn = min(a)
cnt = sum([1 for x in a if x != mn])
print(0 - - cnt // (k - 1))

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:
    loc = i
    break
#print(loc) #locは0index

left = loc
right = N-(loc+1)

ans = left//(K-1) + right//(K-1)
nokori = left%(K-1) + 1 + right%(K-1)
#print(ans,nokori)
if nokori == 1:
  ans += 0
elif nokori <= K:
  ans += 1
else:
  ans += 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import sys
# input = sys.stdin.readline
import collections
import itertools

def main():
    n, k = input_list()
    a = input_list()
    if (n - 1) % (k - 1) == 0:
        print((n-1) // (k-1))
    else:
        v = (n-1) // (k-1)
        print(v + 1)


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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# author:  Taichicchi
# created: 18.09.2020 21:22:11

from math import ceil
import sys

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

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
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 = 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 = list(map(int,input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a = list(map(int,input().split()))
num = a.index(1)
n = M-1
left1= (num)//(M-1)
left2 = n-(num)%(M-1)
right = (N-num-1-left2)//(M-1)
right2 = (N-num-1-left2)%(M-1)
#print(left1,left2,right,right2)
if left2 !=0:
  left1 += 1
if right2 !=0:
  right += 1
print(left1+right)

Submission status: Accepted

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(s/(k-1)) + math.ceil((n-(e+1))/(k-1)))

    print(ans+1)

main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b
def ceil(x):
    return math.ceil(x)
def floor(x):
    return math.floor(x)

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())
al = 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())
aa =  list(map(int, input().split()))
ai = aa.index(min(aa))

x = (ai + 1) // (k -1 )
n = n - (k - 1) * x - 1
y = (n + k -2) // (k-1)

print(x + y)

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,k = i_map()
    a = i_list()
    print(math.ceil((n-1)/(k-1)))

if __name__=="__main__":
    main()

Submission status: Accepted

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

cnt=1
num=k
while num<n:
  num+=(k-1)
  cnt+=1
  
print(cnt)

Submission status: Accepted

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

ans = int((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 = list(map(int, input().split()))

ans = int((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 = 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:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N,K = mint()
A = lint()
print((N-1-1)//(K-1)+1)

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:
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:
a,b=map(int,input().split())

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
As = list(mapint())

times = -(-(N-1)//(K-1))
print(times)

Submission status: Accepted

Solution code:
#34 C - Minimization
N,K = map(int,input().split())
A = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
ceil = lambda a, b: (a + b - 1) // b

n, k = inm()
a = inl()
print(ceil(n-1, k-1))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
ceil = lambda a, b: (a + b - 1) // b

n, k = inm()
a = inl()
start = a.index(1)
ans = 10**9
for i in range(max(0, start-k+1), min(n-1, start+k)):
    ans = min(ans, ceil(i, k-1) + ceil(n-i-1, k-1))
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

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

n, k = inm()
a = inl()
start = a.index(1)
ans = 10**9
for i in range(max(0, start-k+1), min(n-1, start+k)):
    ans = min(ans, ceil(i, k-1) + ceil(n-i-1, k-1))
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,k = LI()
    a = LI()
    index = a.index(1)
    left = index
    right = n-index-1
    ans = float("inf")

    for i in range(k):
        cl = left-i
        cr = right-(k-i-1)
        if cl < 0 or cr < 0:
            continue
        
        cntl = (cl+k-2)//(k-1) if cl!=0 else 0
        cntr = (cr+k-2)//(k-1) if cr!=0 else 0
        cnt = cntl+cntr+1
        ans = min(ans,cnt)

    print(ans)
    
main()

Submission status: Accepted

Solution code:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
min_a = min(a)
x=0
for i,ai in enumerate(a):
  if ai==1:
    break
  x += 1

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

Submission status: Accepted

Solution code:
import math as mt
N,M=list(map(int,input().split()))
if N==M:
  print(1)
  exit()
L=list(map(int,input().split()))
Z=L[0:M]
S=L[::-1]
A=S[0:M]
if len(L)%2==0:
  print(mt.floor((N-M)//(M-1))+2)
else:
  if min(L) in A or min(L) in Z:
    print(mt.floor((N-M)//(M-1))+2)
  else:
    print(mt.floor((N-M)//(M-1))+1)

Submission status: Accepted

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

cnt = 1
while n > 0:
    n -= k
    if n > 0:
        n += 1
        cnt += 1
print(cnt)

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:
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
saishou=A.index(1)
if saishou==0 or saishou==N-1:
    answer=math.ceil((N-1)/(K-1))
    print(answer)
elif saishou+1<=K:
    answer=1+math.ceil((N-K)/(K-1))
    print(answer)
elif N-saishou<=K:
    answer=math.ceil((N-K)/(K-1))+1
    print(answer)
elif (N-K)%(K-1)==0:
    answer=1+(N-K)//(K-1)
    print(answer)
else:
    print(math.ceil(saishou/(K-1))+math.ceil((N-1-saishou)/(K-1)))

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
index_1 = A.index(1)
N -= K
ans = 1
while N > 0:
    N -= K - 1
    ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
if n == k:
    ans = 1
else:
    while n > k:
        n = n - k + 1
        ans += 1
    if n > 0:
        ans += 1
print(ans)

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 = map(int, input().split())
a = list(map(int, input().split()))

for i in range(100000):
    if n <= k:
        print(i + 1)
        break
    else:
        n -= k - 1

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 1
for i in range(K, N, K - 1):
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n, k = list(map(int, input().split()))
a = list(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()))

left = math.ceil(a.index(min(a)) / (k - 1))
surplus = (k-(a.index(min(a)) % (k - 1))) % k + 1
right = math.ceil((len(a)-a.index(min(a))-surplus)/(k-1))
print(left+right)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = [int(i) for i in input().split()]
print(1 + (max(0, N - K) + (K-2))//(K-1))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# AtCoder Regular Contest 099
# C - Minimization 

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

ans=0

a=N-K
ans+=1

if a>0:
    ans+=a//(K-1)
    if a%(K-1)==0:
        pass
    else:
        ans+=1
else:
    pass

print(ans)

Submission status: Accepted

Solution code:
# AtCoder Regular Contest 099
# C - Minimization 
N,K =map(int,input().split())
A=list(map(int,input().split()))

ans=0

a=N-K
ans+=1

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
res=n
for i in range(n):
    if a[i]==1:
        res=i
        break

x=(res+k-2)//(k-1)
y=(max([0,n-1-x*(k-1)])+k-2)//(k-1)
print(x+y)

Submission status: Accepted

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

left = idx
right = n-idx-1
ans = (left+(k-1)-1)//(k-1) + (right+(k-1)-1)//(k-1)

if left%(k-1)+right%(k-1)+1<=k:
    if left%(k-1) > 0 and right%(k-1) > 0:
        ans-=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
num=k
cnt=1
while(n>num):
    num+=(k-1)
    cnt+=1
print(cnt)

Submission status: Accepted

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

a.sort()

ans=1
n=n-k

while n>0:

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

Submission status: Accepted

Solution code:
import collections
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = collections.Counter(A)[min(A)]
print(-(-(N-B)//(K-1)))

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
for i,num in enumerate(a):
    if num==1:
        break
j = i % (k-1)
ans = 0
if j>0:
    ii = i+(k-1-j)
    ans = i//(k-1) + 1
else:
    ii = i
    ans = i//(k-1)
ans += (n-1-ii) // (k-1) + int((n-1-ii)%(k-1)!=0)
print(ans)

Submission status: Accepted

Solution code:
# import sys
# input = sys.stdin.readline
# import re
import math
import itertools

def main():
    n, k, = input_list()
    a = input_list()
    if (n-1) % (k-1) == 0:
        print((n-1)//(k-1))
    else:
        print((n-1)//(k-1) + 1)

# 累積和
def get_camulative(l):
    return [0] + list(itertools.accumulate(l))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def count(mazes, hc, wc):
    hc = list(hc)
    wc = list(wc)
    r = 0
    for hi, row in enumerate(mazes):
        if hi in hc:
            continue
        for wi, m in enumerate(row):
            if wi in wc:
                continue
            if m == '#':
                r += 1
    return r

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

# 最初
N = N - K

if N == 0:
    print(1)
else:
    print(math.ceil(N/(K-1))+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n ,k = I2()
    a = Intl()
    #minは1なのである要素から1までの距離を考えて、それをk-1で割った商が置き換え回数
    print(math.ceil((n - 1)/(k - 1)))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, k, *a = map(int, open(0).read().split())
print(-(-(n - 1) // (k - 1)))

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())
l = list(map(int, input().split()))
if sum(l) == len(l):
  print(0)
elif n==k:
  print(1)
else:
  print((n-1+k-2)//(k-1))

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,k=I()
a = l()
x = a.index(1)
if n == k:
    print(1)
    sys.exit()

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

Submission status: Accepted

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

n = n - k
if n == 0:
    print(1)
else:
    print(1 + math.ceil(n/(k-1)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
N,K=map(int, input().split())
A = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
import heapq as hq
gcd = math.gcd
n,k = ma()
A = list(ma())
mi = min(A)
cnt = 0
ans = 0
f = True #これまでにmiが含まれていないか
for a in A:
    if a==mi:
        if f or cnt==0:
            f = False
            continue
    cnt+=1
    if cnt ==k-1:
        ans+=1
        cnt=0
        f=True
if cnt>0:ans+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil

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

X=A.index(1)

M=float("inf")
for i in range(N):
    if i<=X<=i+K-1:
        P=ceil(i/(K-1))
        Q=ceil((N-i-1)/(K-1))
        M=min(M,P+Q)
print(M)

Submission status: Accepted

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