/
25972.go
61 lines (50 loc) · 905 Bytes
/
25972.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
// Greedy
// https://www.acmicpc.net/problem/25972
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var bw *bufio.Writer = bufio.NewWriter(os.Stdout)
type Domino struct {
// a 좌표, l 높이
a, l int
}
func Fn() {
N := scanInt()
dominos := make([]Domino, 0)
for i := 0; i < N; i++ {
a, l := scanInt(), scanInt()
dominos = append(dominos, Domino{a, l})
}
// 좌표기준 정렬
sort.Slice(dominos, func(i, j int) bool {
return dominos[i].a < dominos[j].a
})
cnt, idx := 1, 0
for {
LA:
curDomino := dominos[idx]
curA, curL := curDomino.a, curDomino.l
if idx+1 == N {
break
}
idx++
for {
// 다음 도미노를 쓰러뜨릴수 있으면 goto 아니면 카운팅
if curA+curL >= dominos[idx].a {
goto LA
} else {
cnt++
break
}
}
if idx >= N {
break
}
}
fmt.Println(cnt)
}