STICKS - Editorial

Try this test:
1
4
1 2 3 3
Your solution output 0, but must be -1

BTW, change for(i=0;i<10002;i++) to for(i=0;i<10001;i++), your arrays size only 10001

You forget about square:
1

4

1 1 1 1

Your solution output -1, but must be 1.

1 Like

You forget about square case too

can u elaborate more ,which case i have omitted

1

4

1 1 1 1

ok,I got it …thank U

1

8

1 1 2 2 2 2 3 3

Answer is 6 = 2 * 3, but your output will be 2 * 2 = 4

@mgch Thanks :slight_smile:

1 Like

Can any one please help me I am getting wrong answer on the following python code:

for _ in range(int(input())):
    n = int(input())
    a = sorted(list(map(int,input().split())))
    l,b = [],[]
    for i in range(n-1,-1,-1):
        if a[i] not in l:
            l.append(a[i])
        elif a[i] in l and a[i] not in b:
            b.append(a[i])
            if len(b)==2:
                break
    if len(b)==2:
        print(b[0]*b[1])
    else:
        print(-1)

try this case
1
4
1 2 2 2

your output: 4
actual output : -1

Whats wrong in my code?

cook your dish here

from collections import deque
t=int(input())
def rect(l):
l1=[]
max_area=[]
q=deque(l1)
mul=1
counter=0
k=0
for i in range(0,len(l),1):
if l[i] not in q:
q.append(l[i])
else:
counter+=1
q.remove(l[i])
if counter==2:
k=1
if counter<=2:
mul=int(mul)*int(l[i])
else:
max_area.append(mul)
mul=1
counter=1
mul=int(mul)*int(l[i])

max_area.append(mul)
if k==0:
    return -1
else:
    return max(max_area)

while t>0:
n=int(input())
l=list(map(int,input().split()))
area=rect(l)
print(area)
t-=1

ink to question https://www.codechef.com/problems/STICKS
here is my code .
I have put comment lines which indicated the purpose
and and since am a beginner here my Time limit is a lot but i will optimise it more but here am getting WA which i am unable to understand.
link to solution.
[CodeChef: Practical coding for everyone ]
i tried the cases in these replies and output was correct

Why is my solution wrong ?
https://www.codechef.com/viewsolution/29242355

It fails in the following test case: (and a couple others which were generated, about 80% correct)
MY OUTPUT: 8645
ANSWER: 9025
1
100
81 50 30 4 75 58 19 51 20 9 78 95 72 71 37 44 37 88 36 31 39 60 45 27 95 30 55 53 92 50 27 21 19 74 58 58 78 56 26 6 4 66 79 48 84 31 10 99 95 90 65 68 49 57 26 39 44 28 18 51 91 16 51 72 50 43 29 95 56 66 58 73 22 19 100 8 79 36 20 91 16 45 19 77 39 49 33 34 33 8 23 14 8 86 28 7 55 12 63 50

thanks :grin:

Hello everyone
https://www.codechef.com/viewsolution/32930212
Can anyone please let me know what is wrong in this code.
Thanks in advance!!

Try this test case:

1
8
1 1 1 1 2 2 2 2

1 Like

https://www.codechef.com/viewsolution/33577069
Can anyone please help?? what is wrong with this C++ code?? It is implemented same as editorial?

can’t help with C++

https://www.codechef.com/viewsolution/33577069
Can anyone please help?? what is wrong with this C++ code?? It is implemented same as editorial?

bro they are considering square also as rectangle in this question

A square is a quadrilateral with all four angles right angles and all four sides of the same length. So a square is a special kind of rectangle , it is one where all the sides have the same length. Thus every square is a rectangle because it is a quadrilateral with all four angles right angles.