-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy path10026.go
55 lines (49 loc) · 975 Bytes
/
10026.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
// UVa 10026 - Shoemaker's Problem
package main
import (
"fmt"
"io"
"os"
"sort"
)
type job struct{ no, time, fine int }
func output(out io.Writer, jobs []job) {
first := true
for _, j := range jobs {
if first {
first = false
} else {
fmt.Fprint(out, " ")
}
fmt.Fprint(out, j.no)
}
fmt.Fprintln(out)
}
func main() {
in, _ := os.Open("10026.in")
defer in.Close()
out, _ := os.Create("10026.out")
defer out.Close()
var kase, n int
first := true
for fmt.Fscanf(in, "%d", &kase); kase > 0; kase-- {
fmt.Fscanf(in, "\n%d", &n)
jobs := make([]job, n)
for i := range jobs {
fmt.Fscanf(in, "%d%d", &jobs[i].time, &jobs[i].fine)
jobs[i].no = i + 1
}
sort.Slice(jobs, func(i, j int) bool {
if jobs[i].time*jobs[j].fine == jobs[j].time*jobs[i].fine {
return i < j
}
return jobs[i].time*jobs[j].fine < jobs[j].time*jobs[i].fine
})
if first {
first = false
} else {
fmt.Fprintln(out)
}
output(out, jobs)
}
}