We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
intworkbook(intn,intk,vector<int>arr){intpage=0,special=0;for(inti=0;i<n;i++){intcur=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.elsecur+=arr[i];//else only arr[i] no:of problems are there in this page.page++;// no: of problems are calculated and page is incrementedif(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;}}returnspecial;}
Lisa's Workbook
You are viewing a single comment's thread. Return to all comments →