Wrong ans in 1 test case

#include
using namespace std;

bool poss(int a[],int n,int s,int minpg){
int st=1;
int pgs=0;
for(int i=0;i<n;i++){
if(pgs+a[i]>minpg){
st++;
pgs=a[i];
if(st>s){
return false;
}
}
else{
pgs+=a[i];
}
}
return true;
}

int main () {
int n,m;
cin>>n>>m;
int a[n];
int t=0;
for(int i=0;i<n;i++){
cin>>a[i];
t+=a[i];
}
int s=a[n-1];
int e=t;
int ans=t;
while(s<=e){
int mid=(s+e)/2;
if(poss(a,n,m,mid)){
ans=mid;
e=mid-1;
}
else{
s=mid+1;
}

}
cout<<ans<<endl;
return 0;

}

hello @mansi25

use long long in place of int
ur updated code->

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.