forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLisa'sWorkbook.java
More file actions
33 lines (31 loc) · 763 Bytes
/
Lisa'sWorkbook.java
File metadata and controls
33 lines (31 loc) · 763 Bytes
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
33
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int t[]=new int[n];
for(int i=0;i<n;i++){
t[i]=sc.nextInt();
}
int page=1;
int p,s,count=0;
for(int i=0;i<n;i++){
p=t[i]/k;
s=1;
while(p--!=0){
if(page>=s&&page<=s+k-1)
count++;
s+=k;
page++;
}
if(t[i]%k!=0){
if(page>=s&&page<=t[i])
count++;
page++;
}
}
System.out.println(count);
}
}