-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11728.go
53 lines (49 loc) · 911 Bytes
/
11728.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
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
var (
w = bufio.NewWriter(os.Stdout)
r = bufio.NewReader(os.Stdin)
)
func main() {
defer w.Flush()
var N, M int
var aPointer, bPointer int
fmt.Fscanf(r, "%d %d\n", &N, &M)
A := getInts()
B := getInts()
for {
if aPointer >= N && bPointer >= M {
break
} else if aPointer >= N {
fmt.Fprintf(w, "%d ", B[bPointer])
bPointer++
} else if bPointer >= M {
fmt.Fprintf(w, "%d ", A[aPointer])
aPointer++
} else {
if A[aPointer] < B[bPointer] {
fmt.Fprintf(w, "%d ", A[aPointer])
aPointer++
} else if A[aPointer] >= B[bPointer] {
fmt.Fprintf(w, "%d ", B[bPointer])
bPointer++
}
}
}
}
func getInts() []int {
s, _ := r.ReadString('\n')
s = strings.TrimSuffix(s, "\n")
t := strings.Fields(s)
res := make([]int, len(t))
for i := range t {
res[i], _ = strconv.Atoi(t[i])
}
return res
}