Return to problem list

2015-qual Problem A

Final solution

cmd.go:
save   open on GitHub
// package, import, etc...

func start() {
	var t int
	mustReadLineOfInts(&t)
	for i := 0; i < t; i++ {
		line := strings.Split(mustReadLine(), " ")
		sMax := mustAtoi(line[0])
		audArray := make([]int, 0, len(line[1]))
		for _, n := range line[1] {
			audArray = append(audArray, mustAtoi(string(n)))
		}
		var numInsertion int
		var numStoodUp int
		for sLevel, numPpl := range audArray {
			if sLevel <= numStoodUp {
				numStoodUp += numPpl
				if numStoodUp >= sMax {
					break
				}
			} else {
				numInsertion += sLevel - numStoodUp
				numStoodUp += sLevel - numStoodUp + numPpl
			}
			// debug(fmt.Sprintf("at sLevel = %v: numStoodUp = %v, numInsertion = %v", sLevel, numStoodUp, numInsertion))
		}
		stdout.WriteString(fmt.Sprintf("Case #%d: %d\n", i+1, numInsertion))
	}
}

// boilerplate omitted...