#include
using namespace std;
bool check(int board[],int n,int painters,int mid){
int temp[n];
for(int i=0;i<n;i++){
temp[i]=board[i];
}
int count=0,i=0;
while(i<n){
for(int j=0;j<painters;j++){
if(i+j>=n){
break;
}
//cout<<temp[i+j]<<" “<<count<<” “<<mid<<endl;
temp[i+j]–;
}
count++;
//cout<<count<<” "<<mid<<endl;
if(temp[i]==0){
i++;
}
if(count>mid){
return false;
}
}
return true;
}
int time(int board[],int n,int painters){
int s=board[n-1];
int e=board[n-1]*n;
int ans;
while(s<=e){
int mid=(s+e)/2;
if(check(board,n,painters,mid)){
//cout<<mid<<endl;
e=mid-1;
ans=mid;
}
else{
s=mid+1;
}
}
return ans;
}
int main() {
int painters,n;
cin>>painters>>n;
int board[n];
for(int i=0;i<n;i++){
cin>>board[i];
}
cout<<time(board,n,painters);
}
only 1 test case is right help