-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf_round891_div3_B.java
67 lines (44 loc) · 1.22 KB
/
cf_round891_div3_B.java
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
import java.util.*;
import java.io.*;
public class cf_round891_div3_B {
static int[] solve(int n, int[] b){
HashSet<Integer> set = new HashSet<>();
for(int i=0; i<b.length; i++){
set.add(b[i]);
}
int x = 0;
int a[] = new int[n];
int sum = 0;
for(Integer it : set){
a[x++] = it;
sum += Math.abs(it);
}
a[n - 1] = sum;
if(set.size() == 1){
int ele = 0;
for(Integer it : set){
ele = it;
}
for(int i=1; i<n-1; i++){
a[i] = ele;
}
}
return a;
}
public static void main(String[] args)throws IOException {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=1; i<=t; i++){
int n = sc.nextInt();
int[] b = new int[n*(n-1)/2];
for(int j=0; j<b.length; j++){
b[j] = sc.nextInt();
}
int[] res = solve(n, b);
for(int k=0; k<res.length; k++){
System.out.print(res[k]+" ");
}
System.out.println();
}
}
}