Painter problem

#include
using namespace std;
#define ll long long int
bool partition(ll a[],ll n,ll k,ll ans)
{
int painter=1;
ll length=0;
for(int i=0;i<n;i++)
{
if(length+a[i]>ans)
{
length=a[i];
painter++;
if(painter>k)
{
return false;
}
}
else
{
length+=a[i];
}
}
return true;
}
ll binarysearch(ll a[],ll n,ll k)
{
ll length=0;
ll s=0,e=0;
for(int i=0;i<n;i++)
{
length+=a[i];
s=max(s,a[i]);
}
e=length;
ll update_ans=0;
while(s<=e)
{
ll mid=(s+e)/2;
if(partition(a,n,k,mid))
{
update_ans=mid;
e=mid-1;
}
else
{
s=mid+1;
}
}
return update_ans;
}
int main() {
ll n;
ll k;
ll t;
cin>>n>>k>>t;
ll a[100001];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<<binarysearch(a,n,k)*t<<endl;
return 0;
}
only 1 test case pass.
what is wrong in my code?
I USE LOGIC OF BOOK ALLOCATION .
APPLY SAME HERE.
IS SAME LOGIC VALID HERE?

I have edited your code, There was only a single correction in line no 62 of your code as it is mentioned in the question that you have to take mod value, so use : cout<<(binarysearch(a,n,k)*t)%10000003<<endl;

Refer to this code and then try to submit it, I have made the changes already…