-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeChef_Sticks.cpp
More file actions
61 lines (52 loc) · 1.07 KB
/
CodeChef_Sticks.cpp
File metadata and controls
61 lines (52 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostream>
using namespace std;
int main()
{
int x,y;
cin>>x;
/*how many test cases*/
for(int a=0;a<x;a++)
{
cin>>y;
int arr[y-1];
for(int b=0;b<y;b++)
{
cin>>arr[b];
/*length of sticks*/
}
int l=0,w=0;
for(int c=0;c<(y-1);c++)
{
for(int d=c+1;d<=(y-1);d++)
{
if(arr[c]>arr[d])
{
int s=arr[d];
arr[d]=arr[c];
arr[c]=s;
}
}
}
int s=0;
for(int c=(y-1);c>=0;c--)
{
if(arr[c]==arr[c-1])
{ if(s>=4)
break;
if(s==0)
l=arr[c];
else
w=arr[c];
s=s+2;
c=c-1;
}
}
if(s==4)
{
cout<<(l*w)<<endl;
}
else{
cout<<-1<<endl;
}
}
}