I am not able to pass any test case.
Please tell what is the problem in my code for Painter Problem
int main() {
int n,k,t;
cin>>n>>k>>t;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
long long s=*max_element(a, a + n),e=(accumulate(a,a+n,0)); //removed *t will do in last ,also use long long
long long ans; //use long long to avoid overflow
while(s<=e){
long long mid=(s+e)/2; //use long long to avoid overflow
if(ismid(a,n,k,1,mid)){ //sent 1 instead of t because will multiply at last
ans=mid;
e=mid-1;
}
else s=mid+1;
}
cout<<((ans%10000003)*(t%10000003))%10000003<<endl; //applied % and *t
return 0;
}
We multipled t at last to avoid overflow
can we simply do cout<<(1ll * ans * t)%10000003;
It might overflow ,but u can try
btw incase u didn’t know
(a*b)%x ==((a%x)(b%x))%x
Is there any other way in which we multiply by t while iterating over the array to get time in each step rather than multiplying it in the end??
U have to apply modulo in intermediate steps at many places
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.