-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChefAndSubset.java
61 lines (51 loc) · 1.56 KB
/
ChefAndSubset.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
51
52
53
54
55
56
57
58
59
60
61
package problems.codechef;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by arpit on 18/12/16.
*/
public class ChefAndSubset {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t;
t=Integer.parseInt(br.readLine());
String[]s;
while (t-->0){
s=br.readLine().split("\\s");
System.out.println(solve(Integer.parseInt(s[0]),Integer.parseInt(s[1]),Integer.parseInt(s[2]),Integer.parseInt(s[3])));
}
}
private static String solve(int ...a) {
if (checkSum1(a) || checksum2(a)||checkSum3(a) || checkSum4(a))return "Yes";
else return "No";
}
private static boolean checkSum4(int[] a) {
if (a[0]+a[1]+a[2]+a[3]==0)return true;
return false;
}
private static boolean checkSum3(int[] a) {
for (int i = 0; i < 4; i++) {
for (int j = i+1; j < 4; j++) {
for (int k =j+1; k < 4; k++) {
if (a[i]+a[j]+a[k]==0)return true;
}
}
}
return false;
}
private static boolean checksum2(int[] a) {
for (int i = 0; i < 4; i++) {
for (int j = i+1; j <4 ; j++) {
if (a[i]+a[j]==0)return true;
}
}
return false;
}
private static boolean checkSum1(int[] a) {
for (int x:a){
if (x==0)return true;
}
return false;
}
}