#include
#include <bits/stdc++.h>
using namespace std;
bool isvalid(long int board[], long int k, long int n, long int time){
long int painters = 1;
long int ans =0;
for(int i =0;i<n;i++){
if(board[i] + ans > time){
ans =board[i];
painters++;
if(painters > k){
return false;
}
}
else{
ans+= board[i];
}
}
return true;
}
long int minTime(long int board[], long int n, long int k, long int e){
long int s = board[n-1];
long int mid = 0, ans = INT_MAX;
while(s <= e){
mid = (s+e)/2;
if(isvalid(board, k, n, mid)){
e = mid -1 ;
ans = min(ans, mid);
}
else{
s = mid +1 ;
}
}
return ans;
}
int main() {
long int k, n;
cin>>k>>n;
long int board[n], ms =0;
for(int i =0;i<n;i++){
cin>>board[i];
ms +=board[i];
}
sort(board, board+n);
cout<<minTime(board, n, k, ms)<<endl;
return 0;
}
This solution is showing some wrong testcases, Can you point out the mistake in my code ?