What is wrong with my code

#include
#include
using namespace std;

bool valid(long long int n, long long int k, long long int t,long long int a[],long long int mid, long long int sum)
{
int prod=0,c,tot;
for(int i=0;i<n;i++)
{
if(prod+(a[i]*t)>mid)
{
k–;
prod=0;
if(k==0)
{
return false;
}
}
else
{
prod+=a[i]*t;
}
}
return true;
}

int paint(long long int n,long long int k,long long int t,long long int a[],long long int sum)
{
long long int low=a[n-1]t,high=sumt,ans;
long long int mid;
while(low<=high)
{
mid=(low+high)/2;
if(valid(n,k,t,a,mid,sum))
{
ans=mid;
high=mid-1;
}
else
{
low=mid+1;
}
}
return ans;

}

int main() {
long long int n,k,t,sum=0;
cin>>n>>k>>t;
long long int a[1000005];
for(int i=0;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
sort(a,a+n);
cout<<(paint(n,k,t,a,sum))%10000003;
return 0;
}

Hey,
u are not required to use the time varient in the valid function, you just check wether
prod +arr[i] > mid {
prod = arr[i];
}

u initialised prod = 0 , but because the present board was not painted , so prod = arr[i]

Just multiple the final ans in the paint function by the time
and then take a mod

That will fetch u correct answer
Refer to this code in case of doubts::: it is your codes updated version

First two test cases are still not getting passed

updated a few lines.
This works well

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.