Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <bits/stdc++.h> using namespace std; int main () { int n,k; cin >> n >> k; cout << ((n-1)+(k-2))/(k-1) << endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<iostream> using namespace std; int main(){ int n, k; cin >> n >> k; cout << ((n-1)+(k-2))/ (k-1); }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<stdio.h> int main() { int n,k,sum=0; scanf("%d%d",&n,&k); while(1) { n-=k; sum++; if(n<=0)break; n++; } printf("%d\n",sum); }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n,k,*a=map(int,open(0).read().split()) print((n+k-3)//(k-1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n,k=map(int,input().split()) a=list(map(int,input().split())) print(-(-(n-1)//(k-1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); for(int i = 1;;i++){ n = n-k; if(n <= 0){ System.out.println(i); break; } n++; } } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << 1 + (n - 2) / (k - 1) << endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
print(eval('0--~-'+input().replace(' ','//~-')))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n,k = map(int, input().split()) x=(n-k)//(k-1) y=(n-k)%(k-1) print(x+1) if y==0 else print(x+2)
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 入力 int N = sc.nextInt(); int K = sc.nextInt(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = sc.nextInt(); } int n = N - 1; int k = K - 1; int ans = 0; if (n % k != 0) { ans = (n / k) + 1; } else { ans = n / k; } System.out.println(ans); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <iostream> using namespace std; int main(){ int n,k; cin >> n >> k; int a[n]; for(int i=0;i<n;i++){ cin >> a[i]; } cout << (n-2)/(k-1)+1 << endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); n -= k; k -= 1; int count = 1; while(n > 0){ n -= k; count++; } System.out.println(count); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N,K=list(map(int,input().split())) print(-((1-N)//(K-1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N, K = map(int,input().split()) A_arr = list(map(int, input().split())) print(-(-(N-1)//(K-1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
def main(): n, k = map(int,input().split()) print((n - 2) // (k - 1) + 1) main()
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; cout << (n - 2) / (k - 1) + 1; return 0; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n,k=map(int,input().split()) print(-(-(n-1)//(k-1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n,k=map(int,input().split()) i=1 cnt=0 while i<n: i+=k-1 cnt+=1 print(cnt)
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <bits/stdc++.h> using namespace std; int main(){ int n, k; cin >> n >> k; cout << (n-1+k-1-1)/(k-1) << endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String inputLine = sc.nextLine(); String[] tokens = inputLine.split(" "); int N = Integer.parseInt(tokens[0]); int K = Integer.parseInt(tokens[1]); if(N <= K)System.out.println(1); else System.out.println((int)Math.ceil((N-K)/(double)(K-1))+1); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <bits/stdc++.h> using namespace std; int n, k; int main(){ cin >> n >> k; cout << (n+k-3) / (k-1) << endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n,k = map(int,input().split()) import math print(math.ceil((n-1)/(k-1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
# -*- 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)
PYTHON
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <iostream> using namespace std; int main(){ int n,k; cin>>n>>k; cout<<(((n-1)/(k-1))+((n-1)%(k-1)?1:0))<<endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n,k=map(int,input().split()) input() if n==k: print(1) else: print(1+(n-2)//(k-1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
## n-1 + k-1 -1 = n+k-3が正しい n,k = map(int,input().split( )) print((n+k-3)//(k-1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n, k = map(int, input().split()) s = input() print(-(-(n - 1) // (k - 1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); int ans = (int)Math.ceil((double)(N-1) / (K-1)); System.out.println(ans); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n, k = list(map(int, input().split())) print( (n-1 + k-1 - 1)// (k-1) )
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N, K = map(int, input().split()) A = input() print((N+K-3)//(K-1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n,k=[int(i)-1 for i in input().split()];print(-(-n//k))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N, K = map(int,input().split()) A = map(int, input().split()) print(-(-(N-1)//(K-1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n, k = list(map(int, input().split())) import math print(math.ceil((n - 1) / (k - 1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n,k = map(int,input().split()) a=input() print((n+k-3)//(k-1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n, k = map(int, input().split()) print((n-1)//(k-1)+1 if (n-1)%(k-1) else (n-1)//(k-1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
from math import * N, K = [int(x) for x in input().strip().split()] print(ceil((N-1)/(K-1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<bits/stdc++.h> using namespace std; int main() { int n,k; cin >> n >> k; cout << (n-2)/(k-1)+1; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N,K = map(int,input().split()) A = list(map(int,input().split())) print((N-1+K-2)//(K-1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner in = new java.util.Scanner(System.in); int N = in.nextInt(); int K = in.nextInt(); int d = (N-1)/(K-1); int e = (N-1)%(K-1); if(e == 0) { System.out.print(d); }else { System.out.print(d+1); } in.close(); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << ((n - 1) + (k - 2)) / (k - 1) << endl; //切り上げ }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<bits/stdc++.h> using namespace std; int main() { int n,k; cin>>n>>k; n--; k--; int t=n/k; if(n%k!=0) t++; cout<<t; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; /* 1回の操作でk-1個を最小値に変換 */ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int k = sc.nextInt(); int[] arr = new int[N]; for(int i = 0; i < N; i++) { arr[i] = sc.nextInt(); } int res = 0; while(N > 0) { res++; N = N - k; if(N==0) break; N++; } System.out.println(res); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n, k = map(int, input().split()) aa=input() a = n - k num = -(-a // (k-1)) print(num+1)
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<bits/stdc++.h> using namespace std; int main(){ int n,k; cin>>n>>k; n--;k--; cout<<((n-1)/k+1)<<endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; public class Main { public static void main(String[] args) { // write your code here Scanner sc = new Scanner(System.in); double n = sc.nextInt() - 1; int k = sc.nextInt() - 1; System.out.println((int)Math.ceil(n / k)); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.lang.*; import java.io.*; import java.util.*; class Main{ public static void main(String args[]) throws FileNotFoundException{ Scanner sc=new Scanner(System.in); String buf=sc.nextLine(); String[] sbuf=buf.split(" "); int n=Integer.parseInt(sbuf[0]); int k=Integer.parseInt(sbuf[1]); sbuf=sc.nextLine().split(" "); int[] num=new int[sbuf.length]; for(int i=0; i<sbuf.length; i++){ num[i]=Integer.parseInt(sbuf[i]); } int a=1; int sub=k-1; n-=k; while(n>=sub){ n-=sub; a+=1; } System.out.println( (n>0)? a+1: a); } static void disp(long[] data){ for(int i=0; i<data.length; i++){ System.out.printf("%d ",data[i]); } System.out.println(); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <bits/stdc++.h> using namespace std; int main() { int n,k; cin >> n >> k; cout << (n-2)/(k-1)+1 << endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); int[] A = new int[N]; for(int i = 0; i < N; i++){ A[i] = sc.nextInt(); } sc.close(); if(N==K) System.out.println(1); else{ if((N-1)%(K-1) == 0) System.out.println((N-1)/(K-1)); else System.out.println((N-1)/(K-1) + 1); } } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c[] = new int[a];; for (int i = 0; i < a; i++) { c[i] = sc.nextInt(); } int count = 0; a -= b; count++; while (a > 0) { a = a - (b - 1); count++; } System.out.println(count); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; import static java.lang.Integer.*; //import static java.lang.Long.*; import static java.lang.Math.*; import static java.lang.System.*; public class Main { public static void main(String[] args) { int i,j; Scanner sc = new Scanner(in); int n = parseInt(sc.next()); int k = parseInt(sc.next()); int[] a = new int[n]; for(i=0;i<n;i++) { a[i] = parseInt(sc.next()); } sc.close(); int ans=1; n-=k; out.println(ans+(int)ceil((double)n/(k-1))); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; int res = 1 + (n - 2) / (k - 1); cout << res << "\n"; return 0; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s[] = (new String(in.readLine())).split(" "); int N = Integer.parseInt(s[0]); int K = Integer.parseInt(s[1]); int c; c = (int)Math.ceil((N - 1.0) / (K - 1.0)); System.out.println(c); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double N = sc.nextDouble(); double K = sc.nextDouble(); System.out.println((int)(Math.ceil((N-K)/(K-1)))+1); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#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
PYTHON
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import math n,m=map(int,input().split()) print(math.ceil((n-1)/(m-1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N, K = map(int, input().split()) input() print(((N - 1) + (K - 1) - 1) // (K - 1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N, K = map(int, input().split()) A = list(map(int, input().split())) print(1+(N-2)//(K-1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = Integer.parseInt(sc.next()); int K = Integer.parseInt(sc.next()); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = Integer.parseInt(sc.next()); } int res = (N - 1) / (K - 1); if ((N - 1) % (K - 1) != 0) { res++; } System.out.println(res); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<iostream> using namespace std; int main(){ int n , k; cin >> n >> k; for(int i=0;i<n;i++){ int tmp; cin >> tmp; } cout << (n-2)/(k-1)+1 << endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] a = new int[n]; for(int i=0; i<n; ++i){ a[i] = sc.nextInt(); } int count = 0; count += (n-1) / (k-1); if((n-1)%(k-1) != 0){ count++; } System.out.println(count); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); for (int i=0; i < n; i++){ sc.nextInt(); } int replaceCount = k; int controllCount = 1; while (replaceCount < n){ replaceCount += (k - 1); controllCount++; } System.out.println(controllCount); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.ArrayList; import java.util.Scanner; class Main { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); ArrayList<Integer> a = new ArrayList<>(); for(int i = 0; i < n ; i++){ a.add(sc.nextInt()); } if((n - 1)%(k - 1) != 0){ System.out.println((n - 1)/(k - 1)+1); }else{ System.out.println((n - 1)/(k - 1)); } } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; public class Main { public static void main(String[] args) { Scanner seer = new Scanner(System.in); int n = seer.nextInt(); int k = seer.nextInt(); for(int i = 0; i < n; i++){ seer.nextInt(); } System.out.println((int)Math.ceil((n-1)*1.0/(k-1))); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <iostream> int main(){int n,k;std::cin>>n>>k;std::cout<<(n-k+(k-2))/(k-1)+1;}
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N,K= [int(x) for x in input().split()] print(1+(N-2)//(K-1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N, K = map(int, raw_input().split()) print (N+K-3)/(K-1)
PYTHON
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < a.length; i++) { a[i] = sc.nextInt(); } int sum = k; int cnt = 1; for (int i = 0; ; i++) { if (sum >= n) { break; } sum += (k - 1); cnt++; } System.out.println(cnt); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<iostream> #include<cmath> #include<string.h> using namespace std; int main(){ int N,K,ans; cin >> N >> K; ans = (N+K-3)/(K-1); cout << ans << "\n"; return 0; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import math N, K = map(int, input().split()) A = input() print(math.ceil((N-K)/(K-1))+1)
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] a = new int[n]; for(int i = 0;i < n;i++)a[i]=sc.nextInt(); if((n-1)%(k-1)==0)System.out.println((n-1)/(k-1)); else System.out.println((n-1)/(k-1)+1); } public static int lcm(int x, int y){ return x*y/gcd(x,y); } public static int gcd(int x, int y){ if(x < y)return gcd(y,x); if(y==0)return x; return gcd(y,x%y); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<bits/stdc++.h> using namespace std; int main(){ int N, K; cin >> N >> K; int Sum=K, cnt=1; while(Sum < N){Sum += K-1;cnt++;} cout<<cnt<<endl; return 0; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; cout << (N - 2) / (K - 1) + 1; return 0; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; int ans=(n-1)/(m-1); if((n-1)%(m-1))ans++; cout<<ans; return 0; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import math N,K = [int(i) for i in input().split()] print(math.ceil((N-1)/(K-1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N,K = map(int, input().split()) A = list(map(int, input().split())) print((N-1+K-1-1)//(K-1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <bits/stdc++.h> using namespace std; int main() { double n, k; cin >> n >> k; cout << ceil((n-1)/(k-1)) << endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<stdio.h> int main (void) { int ans,n,k; scanf("%d%d",&n,&k); ans=(n-1)/(k-1); if((n-1)%(k-1)!=0) ans++; printf("%d\n",ans); return 0; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; /* * AtCoder Beginner Contest 101 C */ public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int K = scanner.nextInt(); int[] A = new int[N]; int minNumIndex = 0; for (int i = 0; i < N; i++) { A[i] = scanner.nextInt(); if (A[i] == 1) { minNumIndex = i + 1; } } int count = (N - K) / (K - 1) + 1; int remain = (N - K) % (K - 1); if (remain != 0) { count++; } System.out.println(count); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.next()); int k = Integer.parseInt(sc.next()); int[] a = new int[n]; for (int i = 0; i < n; i++) { int tmp = Integer.parseInt(sc.next()); a[i] = tmp; } int start = n - 1; int ans = 0; while (start > 0) { ans++; start -= k - 1; } System.out.println(ans); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); int N_ = N - K; int K_ = K - 1; int X = N_ / K_; String ZZ = sc.nextLine(); if(N_ % K_ == 0) { System.out.println(X + 1); }else { System.out.println(X + 2); } } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n, k = map(int, input().split()) print(((n - 1) + (k - 2)) // (k - 1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n,k = map(int,input().split()) _ = input() print(1 + -(-(n-k)//(k-1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N,K = map(int,input().split()) input() print(-1*((-1*(N-1))//(K-1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); printf("%d\n", (n + k - 3) / (k - 1)); return 0; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<bits/stdc++.h> using namespace std; int main(){ int n,k; cin>>n>>k; for(int i=0;i<n;i++){ int a; cin>>a; } cout<<(n+k-3)/(k-1)<<endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import math n,k = map(int,input().split()) print(int(math.ceil((n-k)/(k-1)+1)))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N, K = map(int, raw_input().split()) c = 1 s = N-K while(s>0): c += 1 s -= K-1 print c
PYTHON
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
n,k=map(int,input().split()) a=list(map(int,input().split())) print((n+k-3)//(k-1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << (n - 1) / (k - 1) + ((n - 1) % (k - 1) ? 1 : 0); }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
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)
PYTHON
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<bits/stdc++.h> using namespace std; int main() { double n, k; cin >> n >> k; vector<int> a(n,0); cout << ceil((n-1.)/(k-1.)) << endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<iostream> using namespace std; int main() { int N,K; cin >> N >> K; int i = 0; while (i*K - (i - 1) < N) { ++i; } cout << i << endl; return 0; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
#include<bits/stdc++.h> using namespace std; int main(){ int N, K; cin >> N >> K; cout << (N-1)/(K-1) + ((N-1)%(K-1) ? 1 : 0) << endl; return 0; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; import java.util.List; import java.util.ArrayList; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int S = sc.nextInt(); List<Integer> list1 = new ArrayList<>(); int count = 0; for(int i = 0; i < N; i++){ int a = sc.nextInt(); list1.add(a); if(a==1){ count =i; } } if(count%(S-1)+ (N-count-1)%(S-1) ==0){ System.out.println(count/(S-1)+(N-count-1)/(S-1)); }else if( count%(S-1)+ (N-count-1)%(S-1) <= S-1){ System.out.println(count/(S-1)+(N-count-1)/(S-1)+1); return; }else { System.out.println(count/S+(N-count-1)/(S-1)+2); } } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
// C - Minimization #include <bits/stdc++.h> using namespace std; int main(){ int N,K; cin>>N>>K; cout<< (N-1+(K-1)-1)/(K-1) <<endl; }
CPP
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { static int N; static int K; static List<Integer> A = new ArrayList<>(); public static void main(String[] args) { Scanner sc = new Scanner(System.in); N = sc.nextInt(); K = sc.nextInt(); for (int i = 0; i < N; i++) { int Ai = sc.nextInt(); A.add(Ai); } solve(); } static void solve() { // 最初1を含むK個を選んだあと、 // 残りの(N-K)個から(K-1)個のグループがいくつできるか // (a+b-1)/b int answer = 1 + (((N - K) + (K - 1) - 1) / (K - 1)); System.out.println(answer); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.Scanner; /** * * @author psygn */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int K = scanner.nextInt(); String str = scanner.nextLine(); int ans = (N - 1) / (K - 1); if ((N - 1) % (K - 1) > 0) { ans += 1; } System.out.println(ans); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
N,K=map(int,input().split(' ')) print( (N-1+K-2) // (K-1))
PYTHON3
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), k=sc.nextInt(); int[] arr = new int[n]; for (int i=0; i<n; i++) arr[i] = sc.nextInt(); int ans = 0; n = n - k; while (n > 0) { n -= (k-1); ans++; } System.out.println(ans+1); } }
JAVA
p03317 AtCoder Beginner Contest 101 - Minimization
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. Examples Input 4 3 2 3 1 4 Output 2 Input 3 3 1 2 3 Output 1 Input 8 3 7 3 1 8 4 6 2 5 Output 4
6
0
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] arr = new int[n]; int idx = -1; for(int i = 0; i < n; i++) { arr[i] = sc.nextInt(); if(arr[i] == 1) idx = i; } int cnt = 0; int i = 0; while(i < n - 1) { cnt++; i = i + k - 1; } System.out.println(cnt); } }
JAVA