← Home
For problem statement at 0-999/700-799/710-719/718/problemA.txt this is a correct solution, but verifier at 0-999/700-799/710-719/718/verifierA.go ends with All 100 tests passed can you fix the verifier? ```go
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	line1 := strings.Fields(scanner.Text())
	n, _ := strconv.Atoi(line1[0])
	t64, _ := strconv.Atoi(line1[1])
	t := int64(t64)
	scanner.Scan()
	grade := scanner.Text()

	// Find dot position
	pos_dot := -1
	for i := 0; i < n; i++ {
		if grade[i] == '.' {
			pos_dot = i
			break
		}
	}
	len_int := pos_dot
	m := n - 1 - pos_dot

	// Build arr
	offset := m
	max_index := offset + len_int - 1
	arr := make([]int, max_index+1)
	for i := 1; i <= m; i++ {
		arr[offset-i] = int(grade[pos_dot+i] - '0')
	}
	for k := 0; k < len_int; k++ {
		arr[offset+k] = int(grade[pos_dot-1-k] - '0')
	}

	// Compute f[1..m]
	const INF int64 = 2000000000000000000
	f := make([]int64, m+2)
	for i := 0; i <= m+1; i++ {
		f[i] = INF
	}
	f[m+1] = 0 // conceptual
	for i := m; i >= 1; i-- {
		var next_d int
		if i < m {
			next_d = arr[offset - (i+1)] // but use arr
		} else {
			next_d = 0
		}
		if next_d >= 5 {
			f[i] = 1
		}
		var processed int64
		if i < m {
			processed = f[i+1]
		} else {
			processed = 0
		}
		if processed < INF/2 {
			if next_d == 9 {
				f[i] = min(f[i], processed)
			} else {
				new_d := next_d + 1
				if new_d >= 5 {
					f[i] = min(f[i], processed+1)
				}
			}
		}
	}

	// Compute f[0]
	f0 := INF
	next_d := arr[offset-1] // a[1]
	if next_d >= 5 {
		f0 = 1
	}
	var processed int64 = f[1]
	if processed < INF/2 {
		if next_d == 9 {
			f0 = min(f0, processed)
		} else {
			new_d := next_d + 1
			if new_d >= 5 {
				f0 = min(f0, processed+1)
			}
		}
	}
	f[0] = f0

	// Precompute next_non9
	next_non9 := make([]int, max_index+2)
	next_non9[max_index+1] = max_index + 1
	for i := max_index; i >= 0; i-- {
		if arr[i] < 9 {
			next_non9[i] = i
		} else {
			next_non9[i] = next_non9[i+1]
		}
	}

	// min_cost_for_s
	minc := make([]int64, max_index+2)
	for i := 0; i < len(minc); i++ {
		minc[i] = INF
	}
	for jj := 0; jj <= m; jj++ {
		if f[jj] > t {
			continue
		}
		var add_pos int
		if jj == 0 {
			add_pos = offset
		} else {
			add_pos = offset - jj
		}
		s := next_non9[add_pos]
		minc[s] = min(minc[s], f[jj])
	}

	// Find max s with minc[s] <= t
	max_s := -1
	for ss := 0; ss <= max_index+1; ss++ {
		if minc[ss] <= t {
			if ss > max_s {
				max_s = ss
			}
		}
	}

	var output string
	if max_s == -1 {
		output = grade
	} else {
		// Build new_arr
		high := max(max_index, max_s)
		new_arr := make([]int, high+1)
		for ii := 0; ii <= max_index; ii++ {
			new_arr[ii] = arr[ii]
		}
		for ii := 0; ii < max_s; ii++ {
			new_arr[ii] = 0
		}
		if max_s > max_index {
			new_arr[max_s] = 1
		} else {
			new_arr[max_s]++
		}

		// Build string
		actual_high := high
		for actual_high >= 0 && new_arr[actual_high] == 0 {
			actual_high--
		}
		if actual_high < 0 {
			output = "0"
		} else {
			// integer part
			int_part := ""
			for idx := actual_high; idx >= offset; idx-- {
				int_part += string(rune('0' + new_arr[idx]))
			}
			if int_part == "" {
				int_part = "0"
			}

			// decimal part
			dec_part := ""
			dec_end := offset - 1
			if dec_end >= 0 {
				for idx := dec_end; idx >= 0; idx-- {
					dec_part += string(rune('0' + new_arr[idx]))
				}
				// remove trailing zeros
				for len(dec_part) > 0 && dec_part[len(dec_part)-1] == '0' {
					dec_part = dec_part[:len(dec_part)-1]
				}
			}

			if dec_part != "" {
				output = int_part + "." + dec_part
			} else {
				output = int_part
			}
		}
	}

	fmt.Println(output)
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
```