Two test cases failing for painter partition problem.Following is the my code

Please help me find out what is wrong with given code.

Hey @keshavthakur676
Please share your code in Coding Blocks IDE

Hey @keshavthakur676
All the testcases except 1 are failing on my side please recheck that you have sent the correct code :slight_smile:

I have sent the correct code only two test cases are failing. Basically I am getting runtime error.

Hey @keshavthakur676
Ur arryay size was small increase it in main()

Also after doing that u will get WA verdict for that multply by t only when u are calculating final answer for the rest ignore it otherwise will lead to overflow

Here

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool check(ll boards[], ll curr_min,ll n, ll k,ll t){
	ll painter=1;
	ll sum=0;
	 t=1;//added this
	for(int i=0;i<n;i++){
		if(sum+boards[i]*t>curr_min){
			painter++;
			sum= boards[i]*t;
			if(painter>k || sum>curr_min){
				return false;
			}
		}
		else{
			sum+=boards[i]*t;
		}
	}
	return true;
}
ll painter(ll boards[], ll n,ll k,ll t){
	ll total_boards=0;
	for(int i=0;i<n;i++){
		total_boards+=boards[i];
	}
	ll s=boards[n-1];
	ll e=total_boards*t;
	ll ans=INT_MAX;
	while(s<=e){
		ll mid=(s+e)/2;
		if(check(boards,mid,n,k,t)){
			ans=min(ans,mid);
			e=mid-1;
		}
		else{
			s=mid+1;
		}
	}
	return ans%10000003;
}
int main(){
	ll n,k,t;
	cin>>n>>k>>t;
	ll boards[100000]; //increased size
	for(int i=0;i<n;i++){
		cin>>boards[i];
	}
	cout<<(painter(boards, n,k,t)*(t%10000003))%10000003;//multply here
}

Now I am getting wrong answer. If I multiply by t there,then I get all test cases wrong

Bro make t=1 in check function ,look at what I pasted

What i did is instead of multiplying t in intermediate steps,multipe it in final step

Thanks I got it.I was not taking t=1

1 Like

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.

hello @keshavthakur676 isn’t your doubt resolved now ?
tell me if you still have any problem ?

No it has been resolved.I by mistake clicked on it. Thanks.