3 test cases failing ! Please help?

TESTCASE # 1 : correct (Time: 0 s)
TESTCASE # 2 : correct (Time: 0 s)
TESTCASE # 3 : correct (Time: 0 s)
TESTCASE # 4 : wrong-answer (Time: 0 s)
TESTCASE # 5 : wrong-answer (Time: 0 s)
TESTCASE # 6 : wrong-answer (Time: 0 s)

the logic of your code seems correct. But it is failing for large values of variables.

The problem is with the multiplication:
(n-count)*y

Here the operands n, y and count are of integer data type.

If you multiply two integer values, the result will be an integer value.

But the actual result of multiplication is coming out in a range greater than that of integer.
So, this code returns wrong value of multiplication(because here you have integer overflow).

Solution:
convert the data type of few variables to long long int.
Your modified code:

bool canStudentcount(long long int count,int n,int m,int x,int y){
// m=m+y;
// int left_coupons=m-count;
long long int new_coupons=(n-count)*y;
new_coupons=m+new_coupons;
long long int maxstudents=new_coupons/x;

if(count>maxstudents)
    return false;
else 
    return true;

}

As we have changed the type of to long long int, so now the result will be of long long int type. Hence, integer overflow has been handled.

Hope, this would help.
Give a like if you are satisfied with my answer.:wink:

1 Like

lovely explanation . thankyou so much