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:
NK = [int(i) for i in input().split()]
N, K = NK[0], NK[1]
A = input()
ans = (N - K) // (K - 1) + 1
if (N - K) % (K - 1) != 0:
    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:
def judge(all_num, cover_num):
    if ((all_num-1) % (cover_num-1)) == 0:
        return int((all_num-1)/(cover_num-1))
    else:
        return int((all_num-1)/(cover_num-1)) + 1


if __name__ == "__main__" :
    n_k = list(map(int, input().split()))
    array = list(map(int, input().split()))
    min_point = judge(n_k[0], n_k[1])
    print(min_point)

Submission status: Accepted

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

length=len(A)



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

Submission status: Accepted

Solution code:
import math

l = input().split()
n = l[0]
k = l[1]
l = input().split()



tmp = int(k)-1
x = math.ceil((int(n)-1)/tmp)
# n/tmp

print(x)

Submission status: Accepted

Solution code:
n, k = [int(w) for w in input().split()]
a = [int(w) for w in input().split()]
t, i = 1, 0
while t < n:
    t += (k -1)
    i += 1
print(i)

Submission status: Accepted

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

count = 1
rem = n-k
while(True):
    if(rem <= 0):
        break
    rem -= k-1
    count += 1
    
print(count)

Submission status: Accepted

Solution code:
N, K = map(int, raw_input().split(' '))

raw_input()


N = N - K
K = K - 1

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n, k = input().split()
n = int(n)
k = int(k)
aa = input().split()


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

Submission status: Accepted

Solution code:
import sys
import math
     
     
def main():
    """
    2 <= K <= N <= 10^5
    1 <= ai <= N
    1 <= i <= N
    """
    N, K = map(int, input().split())
    *A, = map(int, input().split())
 
    #ans = f_K(N, K, A)
    ans = editorial(N, K, A)
    print(ans)
     
     
def test_examples():
    nka_ans = [
        (4, 3, [2, 3, 1, 4], 2),
        (3, 3, [1, 2, 3], 1),
        (8, 3, [7, 3, 1, 8, 4, 6, 2, 5], 4),
    ]
 
    for N, K, A, ans in nka_ans:
        assert editorial(N, K, A) == ans
        assert f_K(N, K, A) == ans
     
     
def test_ans():
    nka_ans = [
        (5, 2, [1, 2, 3, 4, 5], 4),
        (5, 3, [1, 2, 3, 4, 5], 2),
        (5, 2, [5, 4, 3, 2, 1], 4),
        (5, 3, [5, 4, 3, 2, 1], 2),
    ]
     
    for N, K, A, ans in nka_ans:
        assert editorial(N, K, A) == ans
        assert f_K(N, K, A) == ans
     
     
def f_K(N, K, A):
    """
    最初に置く範囲は、 1_idx - K + 1 から 1_idx
    """
    idx = [i for i, a in enumerate(A) if a == 1][0]
    left_idx = max(0, idx - K)
    ans = float("inf")
    for i in range(left_idx, idx + 1):
        left = i
        right = max(0, N - left - K)
        tmp = (left + (K - 1) - 1) // (K - 1)
        tmp += 1
        tmp += (right + (K - 1) - 1) // (K - 1)
        ans = min(ans, tmp)
     
    return ans
     
     
def editorial(N, K, A):
    """
    端から端までカバーしていく
    K + (K - 1) * N (N >= 0)
    これは仮に１番左に1があったとき
    結果的には順番は気にしなくて良い
    上記でカバーしていくと、いつかは最初の1をカバーする
        カバーした順番を1をカバーしたことを最初に行えば変わらない
     
    TODO: editorial pdfの意味
        1 + g(K − 1) ≤ p ≤ 1 + (g + 1)(K − 1) なる整数 g
    """
    return ((N-1) + (K-1) - 1) // (K-1)
     
     
     
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

I = A.index(1)

left = I
right = N - I - 1

left_q, left_r = divmod(left, K-1)
right_q, right_r = divmod(right, K-1)

res = math.ceil((left_r+right_r)/(K-1))
print(res + left_q + right_q)

Submission status: Accepted

Solution code:
import sys
import math


def main():
    """
    2 <= K <= N <= 10^5
    1 <= ai <= N
    1 <= i <= N
    """
    N, K = map(int, input().split())
    *A, = map(int, input().split())

    #ans = f_K(N, K, A)
    ans = editorial(N, K, A)
    print(ans)


def test_examples():
    nka_ans = [
        (4, 3, [2, 3, 1, 4], 2),
        (3, 3, [1, 2, 3], 1),
        (8, 3, [7, 3, 1, 8, 4, 6, 2, 5], 4),
    ]

    for N, K, A, ans in nka_ans:
        assert editorial(N, K, A) == ans
        assert f_K(N, K, A) == ans


def test_ans():
    nka_ans = [
        (5, 2, [1, 2, 3, 4, 5], 4),
        (5, 3, [1, 2, 3, 4, 5], 2),
        (5, 2, [5, 4, 3, 2, 1], 4),
        (5, 3, [5, 4, 3, 2, 1], 2),
    ]

    for N, K, A, ans in nka_ans:
        assert editorial(N, K, A) == ans
        assert f_K(N, K, A) == ans


def f_K(N, K, A):
    """
    最初に置く範囲は、 1_idx - K + 1 から 1_idx
    """
    idx = [i for i, a in enumerate(A) if a == 1][0]
    left_idx = max(0, idx - K)
    ans = float("inf")
    for i in range(left_idx, idx + 1):
        left = i
        right = max(0, N - left - K)
        tmp = (left + (K - 1) - 1) // (K - 1)
        tmp += 1
        tmp += (right + (K - 1) - 1) // (K - 1)
        ans = min(ans, tmp)

    return ans


def editorial(N, K, A):
    """
    端から端までカバーしていく
        K + (K - 1) * N (N >= 0)
        これは仮に１番左に1があったとき
    結果的には順番は気にしなくて良い
    上記でカバーしていくと、いつかは最初の1をカバーする
        カバーした順番を1をカバーしたことを最初に行えば変わらない

    TODO: editorial pdfの意味
        1 + g(K − 1) ≤ p ≤ 1 + (g + 1)(K − 1) なる整数 g
    """
    return ((N-1) + (K-1) - 1) // (K-1)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math


def main():
    """
    2 <= K <= N <= 10^5
    1 <= ai <= N
    1 <= i <= N
    """
    N, K = map(int, input().split())
    *A, = map(int, input().split())

    ans = f_K(N, K, A)
    #ans = editorial(N, K, A)
    print(ans)


def test_examples():
    nka_ans = [
        (4, 3, [2, 3, 1, 4], 2),
        (3, 3, [1, 2, 3], 1),
        (8, 3, [7, 3, 1, 8, 4, 6, 2, 5], 4),
    ]

    for N, K, A, ans in nka_ans:
        assert editorial(N, K, A) == ans
        assert f_K(N, K, A) == ans


def test_ans():
    nka_ans = [
        (5, 2, [1, 2, 3, 4, 5], 4),
        (5, 3, [1, 2, 3, 4, 5], 2),
        (5, 2, [5, 4, 3, 2, 1], 4),
        (5, 3, [5, 4, 3, 2, 1], 2),
    ]

    for N, K, A, ans in nka_ans:
        assert editorial(N, K, A) == ans
        assert f_K(N, K, A) == ans


def f_K(N, K, A):
    """
    最初に置く範囲は、 1_idx - K + 1 から 1_idx
    """
    idx = [i for i, a in enumerate(A) if a == 1][0]
    left_idx = max(0, idx - K)
    ans = float("inf")
    for i in range(left_idx, idx + 1):
        left = i
        right = max(0, N - left - K)
        tmp = (left + (K - 1) - 1) // (K - 1)
        tmp += 1
        tmp += (right + (K - 1) - 1) // (K - 1)
        ans = min(ans, tmp)

    return ans


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
NK = input()
Ain = input()
s = NK.index(" ")

N = int(NK[0:s])
K = int(NK[s+1:len(NK)+1])
n = N-1
k = K-1
a = int(n/k)
if n%k != 0:
    a += 1
print(a)

Submission status: Accepted

Solution code:
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(n, k, as1):
    if (n-1)%(k-1)==0:
        return (n-1)//(k-1)
    else:
        return (n-1)//(k-1)+1

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_n, str_k] = line.split(' ')
    line = sys.stdin.readline().rstrip()
    as1 = line.split(' ')
    return (int(str_n), int(str_k), [int(a) for a in as1])

def main():
    n, k, as1 = readQuestion()
    answer = solve(n, k, as1)
    print(answer)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def solve(n, k, as1):
    if (n-1)%(k-1)==0:
        return (n-1)//(k-1)
    else:
        return (n-1)//(k-1)+1

def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_n, str_k] = line.split(' ')
    line = sys.stdin.readline().rstrip()
    as1 = line.split(' ')
    return (int(str_n), int(str_k), [int(a) for a in as1])

def main():
    n, k, as1 = readQuestion()
    answer = solve(n, k, as1)
    print(answer)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil

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

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(1,n):
    if n<=k+(k-1)*(i-1):
        print(i)
        exit()

Submission status: Accepted

Solution code:
import sys
N,K = map(int, input().split())
lis = [int(i) for i in input().split()]
if N == 1:
  print(0)
  sys.exit()
if N<=K:
  print(1)
  sys.exit()
ind = lis.index(1)+1
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 = input().split()
n = int(n)
k = int(k)
aa = input().split()
aa = [int(a) for a in aa]
ans = 0
nn = n
f = False
while nn > 0:
    if f:
        nn += 1
    f = True
    ans += 1
    nn -= k
print(ans)

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) is not 0:
    ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding:utf-8

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

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

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
input() # not important
cnt = 1
N-=K
while N > 0:
    N -= K-1
    cnt+=1
print(cnt)

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

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

Submission status: Accepted

Solution code:
n,k = map(int, raw_input().split())
a = map(int, raw_input().split())
p = a.index(1)
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())
li = list(map(int,input().split()))

N -= K

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

print (ans)

Submission status: Accepted

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

c = 0

while True:
    c += 1
    if n - k <= 0:
        break
    n = n - k + 1

print(c)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

import math
import sys

a,b = input().split(" ")

ans = math.ceil((int(a)-1) / (int(b)-1))
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
arr = list(map(int, input().split()))
m = 1

c = 0
ans = 0
for i in arr:
  if i == 1:
    continue
  ans += 1
c += (ans + K - 2) // (K - 1)
print(c)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 土  6/23 21:24:06 2018

# Usage
#
"""
import math
import sys

def get_input():
    input_data = sys.stdin.readlines()
    N, K = input_data[0].split(" ")
    N = int(N)
    K = int(K)
    SEQ = [int(i) for i in input_data[1].split(" ")]

    assert len(SEQ) == N

    return N, K, SEQ

def get_minimum_distance(K, SEQ):
    """
    >>> get_minimum_distance(3, [2,3,1,4])  # doctest: +SKIP
    2
    >>> get_minimum_distance(3, [1,2,3])  # doctest: +SKIP
    1
    >>> get_minimum_distance(3, [7,3,1,8,4,6,2,5])

    """
    init_minimum_pos = SEQ.index(1)
    print("init:", init_minimum_pos)
    # 最小数値よりまずは右側をやっつける
    right_len = len(SEQ) - init_minimum_pos - 1 # because real num is -1 from index.
    operation_num_right = math.ceil(right_len / K)
    print("右に実施する回数", operation_num_right)
    right_adj = right_len % K

    left_len = SEQ.index(1)
    residual = left_len - right_adj
    operation_num_left = math.ceil(residual / K)

    print(operation_num_right+operation_num_left)


if __name__ == '__main__':
    N, K, SEQ = get_input()
    print(math.ceil((N-1)/(K-1)))

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:
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:
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest


if __name__ == '__main__':
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    ans = (n - 1) // (k - 1)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://qiita.com/skcvim/items/9eed47f5483679fa66b1
# 行数
N, K = map(int, input().split())
A = [input().split()]
i = 1
while N-K > 0:
    N = N-K +1
    i = i+1

print(i)


    # if N != K:
    #     N = N-K-1
    #     i = i+1
    # else:
    #     N = N-K
    #     i = i-1

# if N == K:
#      print(1)
# elif N - K <= N/2 :
#     print(2)
# else:
#     print(N-K-1)

# 8 2
# 5
#
# 8 3
# 4
#
# 8 4
# 3
#
# 8 5
# 2
#
# 8 6
# 2
# 8 7

# 7 2
# 4
#
# 7 3
#

Submission status: Accepted

Solution code:
#abc101c

n,k=map(int,raw_input().split())
if n==k:
 print 1
elif (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 = [int(i) for i in input().split()]

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

Submission status: Accepted

Solution code:
def solve(n, k, a):
    return (n+k-3) / (k-1)
assert solve(4, 3, [2,3,1,4]) == 2
assert solve(3, 3, [1,2,3]) == 1
assert solve(8, 3, [7,3,1,8,4,6,2,5]) == 4

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
print solve(n, k, a)

Submission status: Accepted

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


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

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

Submission status: Accepted

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

Submission status: Accepted

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

for g in range(n):
    if(n <= k + (k - 1) * (g - 1)):
        print(g)
        sys.exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

min_idx = A.index(min(A))

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import math
if __name__ == "__main__":
    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    print(int(math.ceil((n-k)/(k-1)))+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:

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

an = input()
an_list = an.split()
min = min(an_list)





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

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import math
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
one_index = nums.index(1)
if k == len(nums):
    print(1)
else:
    print(math.ceil((n-1)/(k-1)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

#n <= k + (k - 1) * (g - 1)
print(ceil((n - k) / (k - 1) + 1))

Submission status: Accepted

Solution code:





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


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


data_list=list(A)

min_index=data_list.index(min(data_list))+1

anser=0

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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()))
cnt=0
idx=A.index(1)
for i in range(2):
    A=A[::-1]
    idx=A.index(1)
    if idx:
        if idx+1<=K:
            cnt+=1
            A[:K]=[1]*K
        else:
            cnt+=(idx-1)//(K-1)+1
            num=cnt*(K-1)+1
            A[:num]=[1]*num
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

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

	print(ans)
	

if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def Minimization(N,K,Alist):
    minindex = Alist.index(min(Alist))
    leftnum = minindex
    rightnum = N - (minindex + 1)
    print(-(-(leftnum+rightnum) // (K-1)))
N,K = list(map(int,input().split()))
Alist = input().split()
Alist = list(map(int,Alist))
Minimization(N,K,Alist)

Submission status: Accepted

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

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

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:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

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

F=0
for i in A:
    if i==1:
        X=F 
        Y=N-(F+1)
        break;
    F=F+1

P=(X+Y)//(K-1)
if (X+Y)%(K-1)>0:
    print(P+1)
else:
    print(P)

Submission status: Accepted

Solution code:
# coding : utf-8

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

# 全部を最小値1にする必要がある
# 1回の操作で最小値を含めるようにして、残りのK-1個の数を変換するようにするのが一番効率が良い
# 最小値を除いたN-1個を(K-1)個ずつ変換していった回数は、割り算して小数点以下を切り上げる
print( -(-(N-1) // (K-1)) )

Submission status: Accepted

Solution code:
info = list(map(int, input().split(' ')))
array = list(map(int, input().split(' ')))

print((info[0]-1+info[1]-2)//(info[1]-1))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(Ans)

Submission status: Accepted

Solution code:
import math
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
minIndex = A.index(min(A))
if K == len(A):
    print(1)
else:
    print(math.ceil((N-1)/(K-1)))

Submission status: Accepted

Solution code:
import math

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

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

print(int(res))

Submission status: Accepted

Solution code:
n,k = (int(i) for i in input().split())
a = [int(i) for i in 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 k == 2:
    print(n-1)
elif k == n-1:
    print(2)
elif (n-k)%(k-1) == 0:
    print((n-k)//(k-1) +1)
else:
    print((n-k)//(k-1) + 2)

Submission status: Accepted

Solution code:
import sys

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

if ((n - 1) % (k - 1)) == 0:
    print((n - 1) // (k - 1))
    sys.exit()

pos = a.index(1)
start = 0
x = 0
if pos < k:
    start = k - 1
    x += 1
else:
    start = pos
    x += pos // (k - 1)
    if (pos % (k - 1)) != 0:
        x += 1

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

Submission status: Accepted

Solution code:
import math

s = input().rstrip().split()

n = int(s[0])
k = int(s[1]) - 1

a = input()

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

elif(n % k == 1):
    print(block - 1)
elif(n == k + 1):
    print(1)
else:
    print(block)

Submission status: Accepted

Solution code:
import math, sys
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(i) for i in input().split()]
A = [int(i) for i in input().split()]

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

Submission status: Accepted

Solution code:
import math

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

count = A.index('1') + len(A)-A.index('1')-1
print(math.ceil(count/(K-1)))

Submission status: Accepted

Solution code:
(lambda N, K, t: print((N - 1) // (K - 1) + t))(*((lambda N, K: [N, K, 1 if (N - 1) % (K - 1) else 0])(*[int(c) for c in input().split()])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8

inputN, inputK = map(int, input().split())
inputA = list(map(int, input().split()))
minNumber = inputN
minPos = 0

if inputN == inputK:
    print (1)
elif inputN <= (inputK-1)*100000 + 1:
    for i in range(2, 100001):
        if inputN <= (inputK-1)*i + 1:
            print (i)
            break
else:

    for i in range(len(inputA)):
        if inputA[i] < minNumber:
            minNumber = inputA[i]
            minPos = i

    splitNumber = (inputN + 1) / (inputK - 1)
    print (int(splitNumber))

Submission status: Accepted

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

tmp= input().rstrip().split(' ')
L = tmp.index("1")

out = L//(K-1) + (N-1-L)//(K-1)

if(L%(K-1)>0):
    out+=1
if((N-1-L)%(K-1)>0):
    out+=1

if ((L%(K-1)==0) or ((N-1-L)%(K-1)==0)):
    pass
elif((L%(K-1) + (N-1-L)%(K-1)) <= (K-1)):
        out -=1
    
print(out)

Submission status: Accepted

Solution code:
import math
N,K = [int(i) for i in input().split()]
a = list(input().split())
m = a.index('1')
if m == 0 or m == N-1:
    print(math.ceil((N-1)/(K-1)))
else:
    res = ((K-1) - m%(K-1))%(K-1)
    print(math.ceil((m)/(K-1)) + math.ceil((N-m-1-res)/(K-1)))

Submission status: Accepted

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

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

min_A = min(A)


ind1 = A.index(1)
len1 = N -ind1
len2 = ind1 + 1

r1= 0
if (len1-1)%(K-1) != 0:
    r1 = 1

r2= 0
if (len2-1)%(K-1) != 0:
    r2 = 1
d = 0



ans1 = (len1-1)//(K-1)+r1 + (len2-1)//(K-1)+r2

ans=[]
ans.append(ans1)
for i in range(1, K):
    ans2 = 0
    r3= 0
    if (len1-i-1)%(K-1) != 0:
        r3 = 1

    r4= 0
    if (len2-((K-1)-i)-1)%(K-1) != 0:
        r4 = 1
    ans2 = (len1-i-1)//(K-1)+r3 + (len2-((K-1)-i)-1)//(K-1)+r4 + 1
    ans.append(ans2)



print(min(ans))

Submission status: Accepted

Solution code:
def m():
    def solve(n,k):
        if n <= k:
            return 1
        tmp = 1
        tmp += (n-k) // (k-1)
        if (n-k) % (k-1) == 0:
            return tmp
        return tmp + 1

    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    pos = a.index(1)
    ans = 1
    if pos <= (k-1) or pos >= (n-k):
        return solve(n,k)
    if (k % 2) == 0:
        div = k // 2
        left = a[:pos+(div-1)]
        right = a[pos+(div-1):]
    else:
        div = k // 2
        left = a[:pos+(div-1)]
        right = a[pos+(div):]
    ans += solve(len(left), k) + solve(len(right),k)
    return ans
print(m())

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
a,b = [int(i) for i in input().split()]
A = list(map(int,input().split()))

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

Submission status: Accepted

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


def retminvalue(syou):
    mini = 0
    mini += syou // (K-1)
    if(syou % (K-1) != 0):
        mini += 1
    return mini

for i in range(N):
    if A[i] == 1:
        p = i+1

if p == 0 or p==(N):
    print(retminvalue(N))
else:
    minlist = [99999 for i in range(K+3)]
    for i in range(K-1):
        minlist[i] =  retminvalue(N-p+i) + retminvalue(p-1-i)
    print(min(minlist))

Submission status: Accepted

Solution code:
import math

n, k = map(int, input().split())
nums = map(int, input().split())
ans = math.ceil((n-k) / (k-1)) + 1
print(ans)

Submission status: Accepted

Solution code:
"""
最小値で置き換えるなら全ての要素が等しくなったら全て最小値
8 3
k-1づつ隣に影響を及ぼせる
1の位置がiだとしたら(i-1)/(k-1)の切り上げと(N-i)/(k-1)の切り上げ
"""
import math

n , k = map(int, input().split())
b = list(map(int,input().split()))
cnt = 1
i = 0
for t in b:
    if t == 1:
        i = cnt
        break
    cnt += 1

result = math.ceil((i-1)/(k-1)) + math.ceil((n-i)/(k-1))
if ((i-1)/(k-1) - math.floor((i-1)/(k-1))) != 0 and ((n-i)/(k-1) - math.floor((n-i)/(k-1))) != 0 and (((i-1)/(k-1) - math.floor((i-1)/(k-1))) + ((n-i)/(k-1) - math.floor((n-i)/(k-1)))) <= 1:
    result -= 1

print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
# スペース区切りの整数の入力
n,k = map(int, raw_input().split())

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

if n<= k:
	print 1
else:
	print int(math.ceil(float(n-k)/float(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:
N, K = map(int, input().split())
A = list(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(i) for i in input().split()]

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

m=math.ceil(l)

print(m)