-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSherlock and Array
More file actions
43 lines (31 loc) · 829 Bytes
/
Sherlock and Array
File metadata and controls
43 lines (31 loc) · 829 Bytes
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
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the balancedSums function below.
def balancedSums(arr):
n = len(arr)
if n==1:
return "YES"
if n==2:
return "NO"
lst1 = [0,arr[0]]
lst2 = [sum(arr)-arr[0], sum(arr)-arr[0]-arr[1]]
for i in range(2,n-1):
lst1.append(lst1[i-1]+arr[i-1])
lst2.append(lst2[i-1] - arr[i])
for i in range(0,len(lst1)):
if lst1[i]==lst2[i]:
return "YES"
return "NO"
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
T = int(input().strip())
for T_itr in range(T):
n = int(input().strip())
arr = list(map(int, input().rstrip().split()))
result = balancedSums(arr)
fptr.write(result + '\n')
fptr.close()