-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path661.go
More file actions
58 lines (51 loc) · 1.07 KB
/
661.go
File metadata and controls
58 lines (51 loc) · 1.07 KB
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
// UVa 661 - Blowing Fuses
package main
import (
"fmt"
"os"
)
type device struct {
on bool
consumption int
}
func main() {
in, _ := os.Open("661.in")
defer in.Close()
out, _ := os.Create("661.out")
defer out.Close()
var n, m, c, tmp int
for kase := 1; ; kase++ {
if fmt.Fscanf(in, "%d%d%d", &n, &m, &c); n == 0 && m == 0 && c == 0 {
break
}
devices := make([]device, n)
for i := range devices {
fmt.Fscanf(in, "%d", &devices[i].consumption)
}
var total, max int
var blown bool
for ; m > 0; m-- {
fmt.Fscanf(in, "%d", &tmp)
if !devices[tmp-1].on {
total += devices[tmp-1].consumption
if total > c {
blown = true
break
}
if total > max {
max = total
}
} else {
total -= devices[tmp-1].consumption
}
devices[tmp-1].on = !devices[tmp-1].on
}
if fmt.Fprintf(out, "Sequence %d\n", kase); blown {
fmt.Fprintln(out, "Fuse was blown.")
} else {
fmt.Fprintln(out, "Fuse was not blown.")
fmt.Fprintf(out, "Maximal power consumption was %d amperes.\n", max)
}
fmt.Fprintln(out)
}
}