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

Solution in Rust (1.42.0) (judge verdict: Wrong Answer)

fn solve() {
    let (n, k): (usize, usize) = (read::<usize>(), read::<usize>());
    let a: Vec<usize> = (0..n).map(|_| read::<usize>()).collect();
    let mut me = std::usize::MAX;
    let mut mi = 0;
    for i in 0..n {
        if me > a[i] {
            me = a[i];
            mi = i;
        }
    }
    let mut l = 0;
    for i in 0..mi {
        if a[i] != me {
            l = i;
            break;
        } else {
            l = mi;
        }
    }
    let mut r = mi;
    for i in mi + 1..n {
        if a[i] != me {
            r = i;
        }
    }
    let mut res = 0;
    let left = mi - l;
    let right = r - mi;
    if left % (k - 1) != 0 {
        res += left / (k - 1) + 1;
    } else {
        res += left / (k - 1);
    }
    if right % (k - 1) != 0 {
        res += right / (k - 1) + 1;
    } else {
        res += right / (k - 1);
    }

    println!("{}", res);
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========