-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1092.go
72 lines (60 loc) · 1.03 KB
/
P1092.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Greedy
// https://www.acmicpc.net/problem/1092
package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
var bw = bufio.NewWriter(os.Stdout)
func Fn() {
N := scanInt()
cranes := make([]int, N)
for i := 0; i < N; i++ {
cranes[i] = scanInt()
}
M := scanInt()
boxes := make([]int, M)
for i := 0; i < M; i++ {
boxes[i] = scanInt()
}
sort.Slice(cranes, func(i, j int) bool {
return cranes[i] > cranes[j]
})
sort.Slice(boxes, func(i, j int) bool {
return boxes[i] > boxes[j]
})
if cranes[0] < boxes[0] {
fmt.Fprintln(bw, "-1")
} else {
time := 0
for len(boxes) != 0 {
idx := 0
for i := 0; i < len(cranes); {
if idx == len(boxes) {
break
} else if cranes[i] >= boxes[idx] {
boxes = append(boxes[:idx], boxes[idx+1:]...)
i++
} else {
idx++
}
}
time++
}
fmt.Fprintln(bw, time)
}
}
func main() {
defer bw.Flush()
sc.Split(bufio.ScanWords)
Fn()
}
func scanInt() int {
sc.Scan()
v, _ := strconv.Atoi(sc.Text())
return v
}