-
Notifications
You must be signed in to change notification settings - Fork 609
/
Copy path1381B.go
46 lines (42 loc) · 790 Bytes
/
1381B.go
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
package main
import (
"bufio"
. "fmt"
"io"
)
// github.com/EndlessCheng/codeforces-go
func CF1381B(_r io.Reader, _w io.Writer) {
in := bufio.NewReader(_r)
out := bufio.NewWriter(_w)
defer out.Flush()
var T, n int
for Fscan(in, &T); T > 0; T-- {
Fscan(in, &n)
a := make([]int, 2*n)
pos := []int{0}
for i := range a {
Fscan(in, &a[i])
if a[i] > a[pos[len(pos)-1]] {
pos = append(pos, i)
}
}
pos = append(pos, 2*n)
a = nil
for i := 1; i < len(pos); i++ {
a = append(a, pos[i]-pos[i-1])
}
dp := make([]bool, n+1)
dp[0] = true
for _, v := range a {
for s := n; s >= v; s-- {
dp[s] = dp[s] || dp[s-v]
}
}
if dp[n] {
Fprintln(out, "YES")
} else {
Fprintln(out, "NO")
}
}
}
//func main() { CF1381B(os.Stdin, os.Stdout) }