/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
long n=sc.nextLong();
long m=sc.nextLong();
long x=sc.nextLong();
long y=sc.nextLong();
System.out.println(find(n,m,x,y));
}
}
private static long find(long n, long m, long x, long y) {
// TODO Auto-generated method stub
long sum=0;
if(n==1&&m==1)
return x;
if(2*x>y)
{
if(x>y)
x=y;
}
else
y=2*x-1;
if(m%2==0)
{
long div=m/2;
sum=div*y*n;
return sum;
}
if(n%2==0)
{
long div=n/2;
sum=div*y*m;
return sum;
}
//n and m are odd
long div=m/2;
sum=div*y*n;
//System.out.println(sum);
long divn=n/2;
sum+=divn*y;
sum+=x;
return sum;
}
}
Why this code is not working for maximum candies? What am I missing here?