Doubt at around 3:10 minute

In the video Bhaiya said that we can take the space as 0 and the time taken by the fastest cook to make those parathas but wouldn’t that be too less like say if we have a cook with rank 1 and we want 10 parathas the the space will be just between 0 and 10.

Hello @suhaib0900 please wait let me see the video and clearify what actually sir was saying.

@suhaib0900 sir is saying that to avoid this we will take the range as from 0 to 1e18(infinite) so that we don’t experience anything like that.
if we have 10 paranthas to cook and only 1 cook then the range will be from 1 to 55 as the single cook will take 55 minutes to cook all the paranthas but here there can be more then one cook so we can eventually reduce this time much more.

Hi Can you please tell me what is wrong with this code for the Roti Parata problem.

#include <stdio.h>
#include
#include
#include
using namespace std;
//c- num of chef
//req- requirement paratha
//rank - rank of chefs
bool solve(int rank[], int req, int c, int mid)
{
int paratha = 0;

for (int i = 0; i < c; i++)
{
	for (int p = rank[i]; p <= mid; p = p + rank[i])
	{
		paratha++;
	}
}
//cout << endl << "P=" << paratha << endl;
if (paratha >= req)
	return true;

return false;

}
int main() {
// your code goes here
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin); // redirects standard input
freopen(“output.txt”, “w”, stdout); // redirects standard output
#endif
int t;
cin >> t;
while (t–)
{

	int req;
	cin >> req;//Kitna Paratha
	int c;
	cin >> c;//Number of cooks
	int rank[c];
	for (int i = 0; i < c; i++)
	{
		cin >> rank[i];
	}
	sort(rank, rank + c);
	int ans = 0;
	int s = 0;
	/*int e = 0;
	int temp = 0; //temporary request for paratha
	while (temp <= req)
	{
		e = e + rank[0];
		cout << "e = " << e << endl;
		temp++;
	}*/
	int e = (req * req) / 2;

	//	cout << endl << "Val = " << e << endl;
	while (s <= e)
	{	int mid = s + (e - s) / 2;
		//cout << mid;
		if (solve(rank, req, c, mid))
		{
			ans = mid;

			e = mid - 1;
		}
		else
		{
			s = mid + 1;
		}
	}
	cout << ans << endl;
}
return 0;

}

@suhaib0900 check this:

Hi Tushar.
I had a doubt. In the code that you shared are we considering that there will always be a chef with rank 1?

Hello @suhaib0900 read this explanation of the ouput i hope this helps you:
First cook with rank 1 cooks 4 paranthas in 10 minutes (1+2+3+4).
Second cook with rank 2 cooks 3 paranthas in 12 minutes (2+4+6)
Third cook with rank 3 cooks 2 paranthas in 9 minutes (3+6) Fourth cook with rank 4 only needs to cook one last remaining parantha. He can do that in 4 minutes.
Since these cooks cook parallely, the total time taken will be the maximum of the four i.e. 12 minutes.

Okay got it. Thanks! You can close the thread.

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.