Skip to content

Commit 793bc7d

Browse files
committed
By checker
1 parent 1ff71e6 commit 793bc7d

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

boj/1092/main/main.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,69 @@
11
package main
22

3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"sort"
8+
"strconv"
9+
)
10+
311
func main() {
12+
var crains []int
13+
var n, m int
14+
sc := bufio.NewScanner(os.Stdin)
15+
sc.Split(bufio.ScanWords)
16+
sc.Scan()
17+
n, _ = strconv.Atoi(sc.Text())
18+
for i := 0; i < n; i++ {
19+
sc.Scan()
20+
b, _ := strconv.Atoi(sc.Text())
21+
crains = append(crains, b)
22+
}
23+
24+
sc.Scan()
25+
m, _ = strconv.Atoi(sc.Text())
26+
var boxes []int
27+
for i := 0; i < m; i++ {
28+
sc.Scan()
29+
b, _ := strconv.Atoi(sc.Text())
30+
boxes = append(boxes, b)
31+
}
32+
33+
sort.Ints(crains)
34+
crainPos := make([]int, n)
35+
boxCheck := make([]bool, m)
36+
for i, j := 0, len(crains)-1; i < j; i, j = i+1, j-1 {
37+
crains[i], crains[j] = crains[j], crains[i]
38+
}
39+
sort.Ints(boxes)
40+
41+
for i, j := 0, len(boxes)-1; i < j; i, j = i+1, j-1 {
42+
boxes[i], boxes[j] = boxes[j], boxes[i]
43+
}
44+
count := 0
445

46+
if boxes[0] > crains[0] {
47+
fmt.Printf("%d", -1)
48+
return
49+
}
50+
checked := 0
51+
for checked < m {
52+
for i := range crains {
53+
for j := crainPos[i]; j < m; j++ {
54+
if !boxCheck[j] && crains[i] >= boxes[j] {
55+
crainPos[i] = j + 1
56+
boxCheck[j] = true
57+
checked++
58+
break
59+
}
60+
}
61+
}
62+
if count > 10000 {
63+
fmt.Printf("%d", -1)
64+
return
65+
}
66+
count++
67+
}
68+
fmt.Printf("%d", count)
569
}

0 commit comments

Comments
 (0)