online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
/*You are given number of pages in n different books and m students. The books are arranged in ascending order of number of pages. Every student is assigned to read some consecutive books. The task is to assign books in such a way that the maximum number of pages assigned to a student is minimum. */ #include <iostream> #include <stdio.h> using namespace std; bool findMaxNum (int a[],int numBooks,int numStu,int pageNum){ int pageRead=a[0]; int student=1; for(int i=1;i<numBooks;i++){ if(pageRead+a[i]>pageNum){ student++; pageRead=a[i]; if(student>numStu){ return false; } } else{ pageRead+=a[i]; } } return true; } int main() { int testCase; cin>>testCase; for(int i=0;i<testCase;i++){ int numBooks,numStu; cin>>numBooks>>numStu; int bukPagesArr[numBooks]; int sum=0; for(int j=0;j<numBooks;j++){ cin>>bukPagesArr[j]; //each represents number of pages in the jth book sum+=bukPagesArr[j]; } int start=0; int end=sum; int mid; while(start<=end){ mid=(start+end)/2; if(findMaxNum(bukPagesArr,numBooks,numStu,mid)){ end=mid-1; } else{ start=mid+1; } } cout<<mid<<endl; } return 0; } // input // 1 // 4 2 // 12 34 67 90

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text



Program is not being debugged. Click "Debug" button to start program in debug mode.