• + 0 comments
    int workbook(int n, int k, vector<int> arr) {
        int page = 0, special = 0;
        for (int i = 0; i < n; i++) {
            int cur = 0, prev = 0; //cur -> last problem in current page. prev -> last problem in previous page.
            while(arr[i] > 0) {
                prev = cur;
                if (arr[i] > k) 
                    cur += k;  //if arr[i] > k  then k no: of problems are there in current page.
                else 
                    cur += arr[i]; //else only arr[i] no:of problems are there in this page.
                page++; // no: of problems are calculated and page is incremented
                if (page <= cur && page > prev) 
                    special++; //if page no: lies between previous page last problem(exclusive) and current page last problem(inclusive) it is a special problem.
                arr[i] -= k;
            }
        }
        return special;
    }