-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoenixAndGold1515A.java
More file actions
69 lines (56 loc) · 1.2 KB
/
PhoenixAndGold1515A.java
File metadata and controls
69 lines (56 loc) · 1.2 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
62
63
64
65
66
67
68
69
import java.util.Scanner;
public class PhoenixAndGold1515A {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T>0) {
T--;
// take inputs
int n, x;
int [] g = new int [103];
// List<Integer>list = Ints.asList(g);
n = sc.nextInt();
x = sc.nextInt();
for (int i = 0; i < n; ++i) {
g[i] = sc.nextInt();
}
// get sum
int sum = 0;
for(int i = 0; i < n; ++i) {
sum+=g[i];
}
if (sum == x) {
System.out.println("NO");
continue;
}
if (sum < x ) {
System.out.println("YES");
for (int i= 0; i < n; ++i )
System.out.print(g[i] + (i!=(n-1)?" ":"\n"));
continue;
}
sum = 0;
int [] tmp = new int [2000];
int rc = 0;
System.out.println("YES");
for (int i = 0; i < n; ++i) {
sum += g[i];
if (sum == x) {
tmp[rc++] = g[i];
sum = sum - g[i];
continue;
}
System.out.print(g[i] + (i!=(n-1)?" ":""));
}
if (rc == 0)
System.out.println();
else {
for (int i = 0; i < rc; ++i)
System.out.print(" " + tmp [i]);
System.out.println();
}
}
sc.close();
}
}