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:
#101 C
N,K =map(int,input().split())
A =[int(j) for j in input().split()]
cnt = 0
A.sort()
for i in range(len(A)):
    indexes = [i for i, x in enumerate(A) if x == min(A)]
    
    A[max(indexes):max(indexes)+K] = [min(A[max(indexes):max(indexes)+K])] * 3
    cnt+=1
    if A.count(min(A)) == len(A):
        print(cnt)
        exit()

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=[i for i in a if not i==min(a)]
if len(a)%(k-1)==0:
    print(len(a)//(k-1))
else:
    print(len(a)//(k-1)+1)

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split())) #A[0]〜A[N-1]

m = min(A)
answer = N

for i in range(N-K+1): #A[i:i+K]〜A[N-K:N]
  if not m in A[i:i+K]:
    continue
  answer = min(answer,
              (1 + math.ceil(i/(K-1)) + math.ceil((N-K-i)/(K-1))))
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import math
N, K = list(map(int, input().split()))
A = list(map(int, input().split())) #A[0]〜A[N-1]

m = min(A)
answer = N

for i in range(N-K+1): #A[i:i+K]〜A[N-K:N]
  if min(A[i:i+K]) != m:
    continue
  answer = min(answer,
              (1 + math.ceil(i/(K-1)) + math.ceil((N-K-i)/(K-1))))
print(answer)

Submission status: Time Limit Exceeded

Solution code:
k,n=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
#print(k,n,a)
count=1

while n < len(a):
  a=a[n-1:]
  count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
k,n=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
#print(k,n,a)
count=1

while n < len(a):
  a=a[n-1:]
  count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().rstrip().split())
A = list(map(int,input().rstrip().split()))
sum =0
while len(A)>=2:
    sum+=1
    A.insert(K,min(A[:K]))
    del A[0:K]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N,K = list(map(int,input().rstrip().split()))
A = list(map(int,input().rstrip().split()))
sum =0
while len(A)>=2:
    sum+=1
    A.insert(0,min(A[:K]))
    del A[0:K]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
line = list(map(int,input().rstrip().split()))
N = line[0]
K = line[1]
A = list(map(int,input().rstrip().split()))
sum =0
while len(A)>=2:
    sum+=1
    A.insert(0,min(A[:K]))
    del A[0:K]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
def getinputdata():

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

    flg = 1

    try:

        while flg:

            data = input()

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

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

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

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

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

    if len([x for x in arr if x !=mindata])!=0:

        idx=arr.index([x for x in arr if x !=mindata][0])-1
    else:
        break
            
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def solve(array, k):
    ans = 0
    length = len(array)
    i = 0
    while i < length - 1:
        if array[i] == array[i + 1]:
            i += 1
        elif i + k >= length:
            ans += 1
            break
        else:
            ans += 1
            i += k - 1
            array[i] = min(array[:i + 1])
    return ans
    
if __name__ == "__main__":
    n, k = map(int, input().split())
    array = [int(s) for s in input().split()]
    print(solve(array, k))

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split(" "))
lista = list(map(int, input().split(" ")))
num = 0
listlist = []
listlist.append(lista)
r = len(lista) - K + 1
m = min(lista)
while(True):
    num += 1
    newlistlist = []
    for tmplist in listlist:
        for i in range(r):
            tmptmplist = tmplist.copy()
            if min(tmptmplist[i:i+K]) == m and max(tmptmplist[i:i+K]) != m:
                for j in range(K):
                    tmptmplist[i + j] = m
                newlistlist.append(tmptmplist)
    mm = min([sum(listb) for listb in newlistlist])
    if mm == m * N:
        break
    listlist = newlistlist
print(num)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split(" "))
lista = list(map(int, input().split(" ")))
num = 0
listlist = []
listlist.append(lista)
r = len(lista) - K + 1
m = min(lista)
while(True):
    num += 1
    newlistlist = []
    for tmplist in listlist:
        for i in range(r):
            tmptmplist = tmplist.copy()
            if min(tmptmplist[i:i+K]) == m:
                for j in range(K):
                    tmptmplist[i + j] = m
                newlistlist.append(tmptmplist)
    mm = min([sum(listb) for listb in newlistlist])
    if mm == m * N:
        break
    listlist = newlistlist
print(num)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split(" "))
lista = list(map(int, input().split(" ")))
num = 0
listlist = []
listlist.append(lista)
r = len(lista) - K + 1
while(True):
    num += 1
    newlistlist = []
    for tmplist in listlist:
        for i in range(r):
            tmptmplist = tmplist.copy()
            m = min(tmptmplist[i:i+K])
            for j in range(K):
                tmptmplist[i + j] = m
            newlistlist.append(tmptmplist)
    mm = min([len(set(listb)) for listb in newlistlist])
    if mm == 1:
        break
    listlist = newlistlist
print(num)

Submission status: Time Limit Exceeded

Solution code:
A, B = map(int, input().split())
target_list = input().split()

def check_list(lis):
    # print(lis)
    return len(list(set(target_list))) == 1

count = 0
while check_list(target_list) == False:
    min_in_list = min(target_list)
    tmp = A - 1 
    while((target_list[tmp] != min_in_list) or (target_list[tmp] == target_list[tmp-1])):
        tmp -= 1
    min_pos = tmp
    if(min_pos - B) >= 0:
        for i in range(min_pos-(B-1), min_pos):
            target_list[i] = min_in_list
    else:
        for i in range(0, min_pos+1):
            target_list[i] = min_in_list
        for i in range(A-(B-min_pos-1), A):
            target_list[i] = min_in_list

    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
one_index = nums.index(1)
min = n
range_value = one_index if k > one_index else k
for i in range(range_value+1):
    left = one_index - k + i + 1
    right = len(nums[one_index+1:]) - i
    if left + right > n-1:
        break
    else:
        min_tmp = (-(-left//(k-1)))+(-(-right//(k-1)))+1
        if min > min_tmp:
            min = min_tmp
print(min)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
C = 0
A.sort()
while 1:
  for i in range(K):
    A[i] = 1
  A.reverse()
  C += 1
  if all([x == 1 for x in A]):
    break
print(C)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
one_index = nums.index(1)
min = n
for i in range(k):
    left = one_index - i
    right = len(nums[one_index+1:]) + i
    if left + right > n-1:
        continue
    else:
        min_tmp = (-(-left//(k-1)))+(-(-right//(k-1)))
        if min > min_tmp:
            min = min_tmp
print(min)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
import math
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
one_index = nums.index(1)
min = n
for i in range(k):
    left = one_index - i
    right = len(nums[one_index+1:]) + i
    if left + right > n-1:
        continue
    else:
        min_tmp = math.ceil(left/(k-1))+math.ceil(right/(k-1))
        if min > min_tmp:
            min = min_tmp
print(min)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
import math
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
one_index = nums.index(1)
min = n
for i in range(k):
    left = one_index - i
    right = len(nums[one_index+1:]) + i
    if left < 0 or right < 0:
        continue
    else:
        min_tmp = math.ceil(left/(k-1))+math.ceil(right/(k-1))
        if min > min_tmp:
            min = min_tmp
print(min)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
import math
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
one_index = nums.index(1)
result = []
for i in range(k):
    left = one_index - i
    right = len(nums[one_index+1:]) + i
    if left < 0 or right < 0:
        continue
    else:
        result.append(math.ceil(left/(k-1))+math.ceil(right/(k-1)))
print(min(result))

Submission status: Time Limit Exceeded

Solution code:
N,K=(int(i) for i in input().split())
A = list(int(i) for i in input().split())  
minNum=0
i=0
A2=[]
ans=0

A2.extend(A[i:i+K])
while i<N:    
    #print(A2)
    minNum=int(min(A2))
   # print(minNum)
    j=i
    #特定範囲の最小化
    while j<i+K:
        #途中でオーバーしたら逃げる
        if len(A2)<=j:
            break
        #print(A2[j])
        A2[j]=minNum
        j+=1
    if i==0:
        i=i+K
    else:
        i=i+K-1

    ans+=1
    A2.extend(A[i:i+K-1])

#print(A2)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

i_1 = a.index(1)

ans = 9999999999

# left = len(a[:i_1])
# right len(a[i_1+1:)

# if left < k or right <k:
#     c = math.ce

for i in range(1,k+1):
    count = 1
    left = i_1-(k-i)
    right = i_1+i

    if left < 0 or right < 0:
        continue


    l_l = len(a[:left])
    r_l = len(a[right:])

    count += math.ceil(l_l / (k-1)) + math.ceil(r_l / (k-1))
    ans = min(count,ans)

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

minA = min(A)

for i in range(len(A)):
        if A[i] == minA:
                A[i] = 0
        else:
                A[i] = 1

while 1 in A:
        if len(A) <= K:
                ans += 1
                break
        if A[0] == 0:
                if A[1] == 0:
                        A = A[1:]
                elif 0 in A[1:1+K]:
                        A[K] = 0
                        A = A[K:]
                        ans += 1
                else:
                        A[K-1] = 0
                        A = A[K-1:]
                        ans += 1
        else:
                A = A[K-1:]
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

minA = min(A)

for i in range(len(A)):
        if A[i] == minA:
                A[i] = 0
        else:
                A[i] = 1

while sum(A) != 0:
        if len(A) <= K:
                ans += 1
                break
        if A[0] == 0:
                if A[1] == 0:
                        A = A[1:]
                elif 0 in A[1:1+K]:
                        A[K] = 0
                        A = A[K:]
                        ans += 1
                else:
                        A[K-1] = 0
                        A = A[K-1:]
                        ans += 1
        else:
                A = A[K-1:]
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
minIndex = [i for i, x in enumerate(A) if x == min(A)]
print((minIndex[0]+1)//K+(len(A)-max(minIndex[0], 1))//K+1)

Submission status: Time Limit Exceeded

Solution code:
'''WA
N,K=map(int,input().split())
A=list(map(int,input().split()))
x=A.index(1)
K-=1
print((x-1)//K+(N-x-2)//K+2)
'''
N,K=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
while 1:
    idx=A.index(1)
    if idx==0:break
    if idx+1<=K:
        A[:K]=[1]*K
    else:
        A[idx-K+1:idx+1]=[1]*K
    cnt+=1
A=A[::-1]
while 1:
    idx=A.index(1)
    if idx==0:break
    if idx+1<=K:
        A[:K]=[1]*K
    else:
        A[idx-K+1:idx+1]=[1]*K
    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

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

ans = 0

while len(a) > k:
    m = min(a[0:k])
    a = [m] + a[k:]
    ans += 1

print(ans+1)

Submission status: Accepted

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

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

print(cnt)

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

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

for i in range(N):
    if A[i] == 1:
        ans = N
        for j in range(max(0, i-(K-1)), min(N, i+K-1)):
            ans = min(math.ceil(j/(K-1)) + math.ceil((N-j-1)/(K-1)), ans)
        break
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split()) 
num_list = list(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 = 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:
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 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()))
if N == K:
    print(1)
elif (N-1)%(K-1) == 0:
    print((N-1)//(K-1))
elif K == 2:
    print(N-1)
else:
    ans = ceil(N/(K-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 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:
n,k=map(int,input().split())
if n<=k:
	print(1)
else:
	n=n-k
	r=list(map(int,input().split()))
	if n%(k-1)==0:print(1+n//(k-1))
	else:print(2+n//(k-1))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
print(eval('0--~-'+''.join([i if i!=' 'else'//~-'for i in input()])))

Submission status: Accepted

Solution code:
print(eval('0--~-'+''.join([i if i!=' ' else '//~-' for i in input()])))

Submission status: Accepted

Solution code:
print(eval('0--~-'+input().replace(' ','//~-')))

Submission status: Accepted

Solution code:
a=input().split();print(0--~-int(a[0])//~-int(a[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:
n,k=map(int,input().split());print(0--~-n//~-k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 18 09:56:28 2020

@author: liang
"""
from math import ceil

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
ans = ceil((N-K)/(K-1)) + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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:
# -*- coding: utf-8 -*-
# モジュールのインポート
import math


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    # 標準入力を取得
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))

    return N, K, A


def main(N: int, K: int) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 数列の長さ(2 <= K <= N <= 10**5)
        K (int): 選択する要素数(2 <= K <= N <= 10**5)
    """
    # 求解処理
    ans = math.ceil((N - 1) / (K - 1))

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, K, A = get_input()

    # メイン処理
    main(N, K)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import math

# 標準入力を取得
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

# 求解処理
ans = math.ceil((N - 1) / (K - 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:
N, K = map(int, input().split())
A = list(map(int, input().split()))

from math import ceil

print(ceil((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:
# -*- coding: utf-8 -*-
# モジュールのインポート
import math

# 標準入力を取得
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

# 求解処理
x = A.index(1)
y = N - x - 1
ans = math.ceil(x / (K - 1))
if x % (K - 1) != 0:
    y -= K - 1 - (x % (K - 1))
ans += math.ceil(y / (K - 1))

# 結果出力
print(ans)

Submission status: Accepted

Solution code:
import math

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

N -= K
K -= 1
C = math.ceil(N/K)

print(C+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 = list(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:
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:
def main():
    n, k = map(int, input().split())
    a_lst = list(map(int, input().split()))

    tmp = k
    count = 1
    while tmp < n:
        tmp += k - 1
        count += 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
N,K = map(int,input().split())
lsA = 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()))

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

Submission status: Accepted

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


def get_1_index(a):
    for i,j in enumerate(a):
        if j==1:
            return i


index=get_1_index(a)

mae=index
usiro=n-index-1

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

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    if K == 2:
        print(N - 1)
    else:
        ans = 10**10
        for k in range(K):
            v = 0
            if k > 0:
                v += 1
            v += (N - k) // (K - 1)
            if (N - k) % (K - 1) > 1:
                v += 1
            if v < ans:
                ans = v
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array
import numpy as np

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


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

    N, K = il()
    A = il()

    ret = 1
    N -= K
    while not N <= 0:
        N -= K - 1
        ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = n - k
c = 0
if ans > 0:
    c = math.ceil(ans / (k-1))

print(c+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = min(a)
a += [p]
ans,i,temp = 0,0,0
while i<n:
  if a[i]==p:
    m = -(-(i-temp)//(k-1))
    ans += m
    temp += m*(k-1)+1
    i = temp
  else:
    i += 1
ans += -(-(n-temp)//(k-1))
print(ans)

Submission status: Accepted

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

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

#print(i_1)
#print(a[:i_1],a[i_1+1:])
if len(a[:i_1])==0:
    ans = len(a[i_1+1:])//(k-1)
    if len(a[i_1+1:])%(k-1)==0:
        print(ans)
    else:
        print(ans+1)
elif len(a[i_1+1:])==0:
    ans = len(a[:i_1])//(k-1)
    if len(a[:i_1])%(k-1)==0:
        print(ans)
    else:
        print(ans+1)
else:
    ans = len(a[:i_1])//(k-1) + 1
    tmp = ans * (k-1)
    ans += len(a[tmp+1:])//(k-1)
    if len(a[tmp+1:])%(k-1)==0:
        print(ans)
    else:
        print(ans+1)

Submission status: Accepted

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

Submission status: Accepted

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

argmin = A.index(1)

back = (argmin+(K-1)-1)//(K-1)
forward = (N-argmin-1+(K-1)-1)//(K-1)
ans1 = back+forward

ans2 = ((N-1)+(K-1)-1)//(K-1)

print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

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

m = a.index(1)
print(ceil((n-1)/(k-1)))

Submission status: Accepted

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

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

Submission status: Accepted

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

count =0
first = True
while N >=K:
    if  first ==True:
        count +=1
        N-=K
        first =False
        
    else:
        count+=1
        N-=(K-1)
        
   
    

if N!=0:
    count+=1
print(count)

Submission status: Accepted

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

i=A.index(1)+1
if i<=K or i>=N-K:
    ans=(N-K)//(K-1)+1 if (N-K)%(K-1)==0 else (N-K)//(K-1)+2
else:
    for a in range(K):
        b=0 if (i-a)%(K-1)==0 and (N-(i+(K-a)))%(K-1)==0 else 1
    front=i//(K-1)
    back=(N-(i+K))//(K-1)
    ans=front+back+1+b
print(ans)

Submission status: Accepted

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

i=A.index(1)+1
if i<=K or i>=N-K:
    ans=(N-K)//(K-1)+1 if (N-K)%(K-1)==0 else (N-K)//(K-1)+2
else:
    for a in range(K):
        if (i-a)%(K-1)==0 and (N-(i+(K-a)))%(K-1)==0:
            b=0
        else:
            b=1
    front=i//(K-1)
    back=(N-(i+K))//(K-1)
    ans=front+back+1+b
print(ans)

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:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n,k = MI()
a = RI()

# ind = a.index(1)
ans = ceil((n-k)/(k-1)) + 1
print(ans)