-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
69 lines (62 loc) · 1.52 KB
/
Copy pathSolution.java
File metadata and controls
69 lines (62 loc) · 1.52 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.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner in = new Scanner(System.in);
boolean flag = false;
int num = in.nextInt();
ArrayElement e[] = new ArrayElement[num];
for (int i=0;i<num;i++){
int size = in.nextInt();
e[i] = new ArrayElement(size);
e[i].num = size;
e[i].acceptElements();
}
for (int i=0;i<num;i++){
if ( e[i].num == 1)
System.out.println("YES");
else{
for (int j=0;j<e[i].num;j++){
flag = false;
if (e[i].sumStart(j)==e[i].sumLast(j)){
System.out.println("YES");
flag=true;
break;
}
}
if (!flag){
System.out.println("NO");
}
}
}
}
}
class ArrayElement {
int num;
int array[];
ArrayElement(int n){
this.array = new int[n];
}
void acceptElements(){
try {
Scanner in = new Scanner(System.in);
for (int i=0;i<this.num;i++){
this.array[i] = in.nextInt();
}}
catch (Exception e)
{}
}
int sumStart(int index){
int sum = 0;
for (int i =0;i<index;i++)
sum += this.array[i];
return sum;
}
int sumLast(int index){
int sum = 0;
for (int i = index+1;i<num;i++)
sum += this.array[i];
return sum;
}
}