This code is not giving correct answer

#include<bits/stdc++.h>
using namespace std;
int is_possible(int n,int k,int t,int mid,int arr[])
{
int painter=1;
int current_time=0;
for(int i=0;i<n;i++)
{
current_time+=arr[i]*t;
if(current_time>mid)
{
painter++;
current_time=arr[i]*t;
}
}
return painter;
}
int time_req(int n,int k,int t,int arr[])
{
int total_time=0;
for(int i=0;i<n;i++)
{
total_time=total_time+arr[i]*t;
}
int start=arr[n-1];
int ans=INT_MAX;
int end=total_time;
while(start<=end)
{
int mid=(start+end)/2;
int p=is_possible(n,k,t,mid,arr);
if(p>k)
{
start=mid+1;

		}
	
	else
	{
	  ans=min(ans,mid);	
      end=mid-1;
	}
}
return ans;

}
int main()
{
int n,k,t;
cin>>n>>k>>t;
int arr[n]={0};
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
cout<<time_req(n,k,t,arr);
}

Hello @pratyushbhardwaj1998,

Always share your code using some online IDE.
The way you have shared it has introduced syntax errors to it.

STEPS:

  1. Paste your code at: https://ide.codingblocks.com/
  2. Save it there.
  3. Share the URL generated.

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.