-
Notifications
You must be signed in to change notification settings - Fork 0
/
lisaWorkbooks.java
32 lines (30 loc) · 1.24 KB
/
lisaWorkbooks.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class lisaWorkbooks {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scan = new Scanner(System.in);
int n = scan.nextInt(), k = scan.nextInt();//n = chapters, k = max. problems per page
int pg = 1, sProbs = 0;//pg = page number, sProbs = special problems
int array[] = new int[n];//store number of problems per chapter
for(int i = 0; i < n; i++){
array[i] = scan.nextInt();
}
for(int i = 1; i <= n; i++){ //i = chapters
for(int j =1; j <= array[i-1]; j++){//j = problems
//System.out.println("Chapter: " + i + "\nProblem: " + j + "\nPage No.: " + pg + "\n*************************");
if(j == pg){//if problem no. same as page no.
sProbs++;
}
if(j%k == 0 && j != array[i-1]){//if we've reached the max no. of problems per page
pg++;
}
}
pg++;
}
System.out.println(sProbs);
}
}