 # WA in MAXIMUM CANDIES (CHECHOC)

I even checked all the test cases given by people on editorial’s page but I still I don’t know why WA is the verdict!

have you tried writing a random generator and a tester to compare your solutions with correct solutions? I would do that in your place, actually I did and for example for this testcase -> n=6, m=10, x=1, y=7
your output is 210 but correct answer is 60 (x=1 and there are 60 cells so the answer would never be greater than 60)

3 Likes

@aayushvrshney The way you are writing code you may miss some cases( as a case mentioned by @carre ) , so all we have to care about is that what max sum and value cells can handle and this can be found at very beginning of the program and then fill matrix accordingly , here there will be one edge case when `n == 1 && m == 1` that you have also covered in your code.

``````#include <bits/stdc++.h>
using namespace std;

int n, m , x , y , ans ;

void solve()
{
cin >> n >> m >> x >> y ;

if(n == 1 && m == 1)
ans = x;
else
{
x = min( x , y ) ;    ///  WE CAN HAVE ATMOST X IN SINGLE GRID
y = min( 2 * x , y ) ; ///  SUM OF TWO GRIDS CAN BE ATMOST Y AND IT CANNOT EXEED 2*x
ans = ( ( n * m + 1 ) / 2 ) * x + ( n * m / 2 ) * ( y - x ) ;
}

cout << ans << endl ;
}

int main() {
int t;
cin>>t;
while(t--)
solve() ;
}
``````

@carre @pst10 Sir, thanks a lot! Can you please suggest me some good test case generation tools as I don’t know much about this.