-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCF1399C.java
More file actions
59 lines (50 loc) · 1.27 KB
/
CF1399C.java
File metadata and controls
59 lines (50 loc) · 1.27 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
import java.util.*;
import java.util.Map.Entry;
public class CF1399C {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t=0;
if(sc.hasNextInt())
t = sc.nextInt();
for(int h=0;h<t;h++)
{
int n= sc.nextInt();
ArrayList<Integer> list = new ArrayList<>(); // to store weights of all players
for(int i=0;i<n;i++)
{
int x = sc.nextInt();
list.add(x);
}
HashSet<Integer> set = new HashSet<>(); // to store non duplicate sum of weights values
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++) {
int sum = list.get(i)+list.get(j); //storing all possible vlaues of sum
set.add(sum);
}
}
int maxans=Integer.MIN_VALUE;
for(int sum: set) {
int ans=0,i=0,j=0;
boolean[] check = new boolean[n]; //if already checked array
while(i<n)
{
j=i+1;
while(j<n)
{
if(list.get(j)==sum-list.get(i) && check[j]==false && check[i]==false) {
ans++;
check[j] = true;
check[i] = true;
}
j++;
}
i++;
}
maxans = Math.max(maxans, ans); //maximum number of teams
}
System.out.println(maxans);
}
}
}