-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathE0039.cpp
More file actions
38 lines (34 loc) · 693 Bytes
/
E0039.cpp
File metadata and controls
38 lines (34 loc) · 693 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
34
35
36
37
38
/*
Problem Statement: https://www.hackerrank.com/challenges/lisa-workbook/problem
*/
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int workbook(int n, int k, vector<int> arr) {
int special = 0;
int curPage = 1;
for(int i=0 ; i<arr.size() ; i++){
int numOfPages = ceil((float)arr[i]/k);
for(int page=1 ; page<=numOfPages ; page++){
int start = (page-1)*k + 1;
int end = min(page*k, arr[i]);
if(curPage>=start && curPage<=end)
special++;
curPage++;
}
}
return special;
}
int main()
{
int n, k, num;
vector<int> arr;
cin>>n>>k;
for(int i=0 ; i<n ; i++){
cin>>num;
arr.push_back(num);
}
cout<<workbook(n, k, arr);
return 0;
}