-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path076.swift
More file actions
46 lines (42 loc) · 691 Bytes
/
076.swift
File metadata and controls
46 lines (42 loc) · 691 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
44
45
46
func readInt() -> Int {
Int(readLine()!)!
}
func readIntArray() -> [Int] {
readLine()!.split(separator: " ").map { Int(String($0))! }
}
let n = readInt()
let a = readIntArray()
let aSum = a.reduce(0, +)
if aSum % 10 != 0 {
print("No")
} else {
let target = aSum / 10
var start = 0
var end = 0
var current = a[0]
while true {
if current == target {
print("Yes")
break
} else if current < target {
end += 1
if end == n {
end = 0
}
current += a[end]
} else {
if start == n - 1 {
print("No")
break
}
if start == end {
start += 1
end = start
current = a[start]
} else {
current -= a[start]
start += 1
}
}
}
}