STICKS - Editorial

C code
Can any one say me what is wrong with the code…
its working fine in code blocks…but am getting wrong answer warning while submitting.
could anyone please explain??
here is the link
https://www.codechef.com/submit/complete/13211715

Iam getting WA.But it is working fine in code blocks
https://www.codechef.com/viewsolution/13211715
could anyone explain pls

for (int i = 0; i < t; i++) {
br.readLine();
toks = br.readLine().trim().split(" ");
int[] A = new int[toks.length];
for(int j=0; j<toks.length; j++){
A[j] = Integer.parseInt(toks[j]);
}
Arrays.sort(A);
int found = 0;
int ans = 1;
for(int x=A.length-1; x>0; x–){
if(A[x] == A[x-1]){
ans = ans * A[x];
found = found + 2;
x–;
}
if(found == 4){
break;
}
}
System.out.println(found == 4 ? ans : -1);

Hello, I’m trying to understand why this solution is returning a wrong answer.

https://www.codechef.com/viewsolution/18760432

Any feedback would be greatly appreciated :slight_smile:

One thing to note is the question is to find the maximum area of one rectangle. I was taking the maximum possible area of all the rectangles (i.e summing all the areas ).
for example the test case :
8
1 1 1 1 1 1 1 1
output should be 1 not 2 :slight_smile:

This is my implementation. How is it?
#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin>>t;

while(t--)
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    sort(a,a+n);
    int ans=-1;
    int p=1,cnt=0;
    for(int i=n-1;i>=0;i--)
    {
        if(cnt==2)
        {
            break;
        }

        if(a[i]==a[i-1])
        {
            p=p*a[i];
            i--;
            cnt++;
        }
    }

    if(cnt==2)
    {
        cout<<p<<endl;
    }
    else
        cout<<ans<<endl;
}
return 0;

}

@admin , a stupid question, but is making squares allowed with any left over pair of sticks?

Can anyone tell which test case is failed for my code or why I’m getting Wrong Answer
https://www.codechef.com/viewsolution/22156698