-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11722.go
55 lines (50 loc) · 776 Bytes
/
11722.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
47
48
49
50
51
52
53
54
55
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
var (
w = bufio.NewWriter(os.Stdout)
r = bufio.NewReader(os.Stdin)
N int
A []int
D []int
)
func main() {
defer w.Flush()
fmt.Fscanf(r, "%d\n", &N)
D = make([]int, N+1)
A = getInts()
for i := N; i >= 1; i-- {
D[i] = 1
for j := N; j > i; j-- {
if A[i] > A[j] && D[i] < D[j]+1 {
D[i] = D[j] + 1
}
}
}
fmt.Fprintln(w, max(D))
}
func max(arr []int) int {
res := arr[0]
for i := range arr {
if res < arr[i] {
res = arr[i]
}
}
return res
}
func getInts() []int {
s, _ := r.ReadString('\n')
s = strings.TrimSuffix(s, "\n")
s = "0 " + s
t := strings.Fields(s)
res := make([]int, len(t))
for i := 1; i < len(t); i++ {
res[i], _ = strconv.Atoi(t[i])
}
return res
}