In spoj pratha problenm
@sneha23
Firstly, you are running the loop from 1 to n in the minparantha function. This is incorrect because the array is 0 indexed. Secondly, you are making a mistake in calculating the paranthas made. The value in a[i] is the rate, which means the time taken to make the first parantha, not the number of paranthas made in unit time.
For every chef, to calculate the number of paranthas made in time mid, solve the equation,
a[i](1 + 2 + … . . . p) <= mid, where p is the number of paranthas made by ith chef in mid time. Find p by solving this quadratic equation.
If my explanation was able to resolve your doubt, please mark the doubt as resolved.
Please revert in case you face any difficulty.
#include
#include
using namespace std;
int minparatha(int a[],int p,int c,int mid)
{
int chef=1;
int paratha_made=0;
// cout<<mid;
int sum=0;
for(int i=0;i<c;i++)
{
int time=(paratha_made*(paratha_made+1)/2)*a[i];
if( time>=mid)
{
chef++;
if(chef>c)
{
return 0;
}
}
else
{
paratha_made++;
sum=paratha_made+sum;
}
// cout<<sum<<endl;
}
return 1;
}
int paratha(int a[],int p,int c,int max_r)
{
int s=0;
int e=max_rp(p+1)/2;
int time=0;
while(s<=e)
{
int mid=(s+e)/2;
if(minparatha(a,p,c,mid))
{
time=mid;
e=mid-1;
}
else
{
s=mid+1;
}
}
return time;
}
int main()
{
int t;
cin>>t;
int max_r=0;
int p,c;
int a[1000];
for(int i=0;i<t;i++)
{
cin>>p;
cin>>c;
for(int i=0;i<c;i++)
{
cin>>a[i];
}
sort(a,a+c);
max_r=a[c-1];
cout<<paratha( a,p,c,max_r);
}
return 0;
}
still not working properly…pls look once
@sneha23
I advised you to solve for p. You have done something entirely different. p is different for every chef. You have put pratha_made in place of p. p is the required variable, its value is to be determined.
Please solve the above quadratic equation.
Please revert in case you face any difficulty.