Wrong answer in a single testcase

My code is giving wrong answer in a single test case although all the other test cases are giving correct answer. The code is given at https://ide.codingblocks.com/s/281319

hi @souptiksarkar4572 use long long int datatype to store values

I have used long long to store values but it is still giving me error for a single test case. One thing I found out is when only a single chef is given in the array it is giving a garbage value. The binary search function is creating some unnecessary output. While dry running the code it works fine

hi @souptiksarkar4572 i will check for single chef

Thank you very much. I think when middle==end it is not updating the value of ans even though it is satisfying the canMakeParanthas() function.

@souptiksarkar4572
i think e should be this image
(ranks are in sorted order, so in the worst case you should consider the chef with the maximum rank)

Rest all seems correct. You can look at my “check” function as an alternative, rest all is totally fine

bool isEnoughTime(ll parantheRequired, ll numOfCooks, vector<ll> &ranks, ll timeTaken) {

    ll parantheCooked = 0;

    for (ll i = 0; i < numOfCooks; i++) {

        int x = 0;

        while (((x) * (x + 1) * ranks[i])/2 <= timeTaken) {

            x++;

        }

        x--;

        parantheCooked += x;

    }

    return parantheCooked >= parantheRequired;

}

Thank you very much for looking into the problem. I have understood your check function. But wouldn’t the binary search algorithm also satisfy the end case ?

@souptiksarkar4572 we are applying binary search only to look for an appropriate amount of time, but I think check function can be pretty straightforward as we just have to check whether a given value is valid or not. My rest of the program is almost similar to yours.

Okay I got it. Actually till now I was assuming that the worst time required will be the time required by the best chef to cook all the paranthas.
Thank you very much

1 Like

@souptiksarkar4572 if you think about it, the worst time will be when the slowest cook cooked all the paranthas. Please mark the doubt as resolved in case of no further queries :slight_smile: