i am getting 1 less than actual output
Test cases not run
hello @singh.pankhil40
pls save ur code here-> https://ide.codingblocks.com/
and share the link with me.
i have shared it and you can see it
where? …
#include
#include
#include
#include
using namespace std;
bool student(int a[],int n,int m,int mid)
{ long long sum=0;
int ans1=0;
int stu=a[0];
int count=1;
for(int i=0;i<n;i++)
{sum+=a[i];
if(sum<=mid)
{ans1=mid;}
else
{sum=a[i];
stu=a[i];
count++;
if(count>m)
return false;}}
return true;}
int main() {
int t=0;
cin>>t;
while(t>0)
{int n=0,m=0;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
int sum=0;
for(int i=0;i<n;i++)
sum+=a[i];
int s=0;
int e=sum;
int ans=0;
bool pages;
while(s<=e)
{int mid=(s+e)/2;
pages=student(a,n,m,mid);
if(pages==true)
{ans=mid;
e=mid-1;
}
else
s=mid+1;}
cout<<ans;
cout<<endl;
t–;}
return 0;
}
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.