Test Case 4th and 5th is not getting passed. Rest all test cases are passing.
Here’s my code:
#include<bits/stdc++.h>
using namespace std;
#define lli long long
#define f(i,a,b) for(i=a;i<b;i++)
#define r(i,n) f(i,0,n)
#define int lli
#define sf(a) scanf("%lld",&a)
int func(int k, int n, int a[], int mid)
{
int req = 0;
int pp=0;
int curr=0;
while(pp<n){
if(curr<=mid){
curr+=(a[pp]%10000003);
pp++;
}
if(curr>mid){
req++;
pp–;
curr=0;
}
}
if(curr!=0){
req++;
}
return req;
}
signed main(){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
int k;
cin>>k;
int n;
cin>>n;
int t;
cin>>t;
int a[n];
int s=0;
int e=0;
for(int i=0;i<n;i++){
cin>>a[i];
e=e+(a[i]);
if(a[i]>s){
s=a[i];
}
}
int ans;
while(s<e){
int mid = ((s+e)/2);
int req = func(k,n,a,mid);
if(req<=k){
e=mid;
}
else{
s=mid+1;
}
}
ans = s;
cout<<(ans*t)%10000003<<endl;
}