As coding blocks ide is not generating the saved code’s link so used a different online compiler.
here is the link : https://onlinegdb.com/EGRWTdIIg
Why this code is not working?
#include
#include
#include
using namespace std;
bool isPossible(long long int *time, int N, int K,long long int mid)
{
long long int painters = 1, timetaken = 0;
for(int i = 0; i < N; i++)
{
if((timetaken + time[i]) > mid)
{
painters++;
timetaken = time[i];
}
else
timetaken += time[i];
}
if(painters > K)
return false;
return true;
}
long long time_required(long long int time, int N, int K,long long int totaltime,int T)
{
long long int start = INT_MIN;
for(int i=0;i<N;i++){
start = max(start, time[i]);
}
if(K >= N){
return (startT)%10000003;
}
long long int end = totaltime, mid, ans;
while(start <= end){
mid = (start + end)/2;
if(isPossible(time, N, K, mid)){
ans = mid;
end = mid - 1;
}
else
start = mid + 1;
}
return (ans*T)%10000003;
}
int main() {
int N, K, T, length;
long long int totaltime = 0;
cin>>N>>K>>T;
long long int *time = new long long int[N];
for(int i = 0; i < N; i++){
cin>>length;
time[i] = length;
totaltime += time[i];
}
cout<<time_required(time, N, K, totaltime,T)<<endl;
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.