int solve(vector<int>& arr, int n, int mid){
int stu=1, load=0;
for(int i=0; i<n; i++){
if(arr[i]+load>mid){
load = arr[i];
stu++;
}
else{
load +=arr[i];
}
}
return stu;
}
int findPages(vector<int>& arr, int n, int m) {
// Write your code here.
if(m>n)return -1;
int sum =0, maxi = INT_MIN;
for(int i=0; i<n; i++){
sum+=arr[i];
maxi = max(maxi, arr[i]);
}
int ans =-1;
int low = maxi, high = sum;
while(low<=high){
int mid = low+(high-low)/2;
int stu = solve(arr, n, mid);
if(stu <=m){
ans = mid;
high = mid-1;
}
else{
low = mid+1;
}
}
return ans;
}