← Home
For problem statement at 1000-1999/1600-1699/1630-1639/1635/problemB.txt this is a correct solution, but verifier at 1000-1999/1600-1699/1630-1639/1635/verifierB.go ends with test 30 failed
input:
1
20
311713893 433371299 445860653 561953090 374426445 127294849 314871180 475827024 395731013 744405731 894128380 452115167 545365831 894262863 767746742 928402435 265217083 625699826 523714654 908137750
expected:
5
311713893 433371299 445860653 561953090 561953090 127294849 314871180 475827024 744405731 744405731 894128380 894128380 545365831 894262863 928402435 928402435 265217083 625699826 908137750 908137750

got:
5
311713893 433371299 445860653 561953090 561953090 127294849 314871180 475827024 475827024 744405731 894128380 894128380 545365831 894262863 928402435 928402435 265217083 625699826 625699826 908137750


exit status 1 can you fix the verifier? ```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var t int
	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}

		ops := 0
		for i := 1; i < n-1; i++ {
			if a[i] > a[i-1] && a[i] > a[i+1] {
				ops++
				// Check if there is a local maximum at i+2
				if i+2 < n-1 && a[i+2] > a[i+1] && a[i+2] > a[i+3] {
					// We have a pattern like X (bad) Y (bad) Z
					// Changing the middle element Y allows fixing both X and Z in 1 operation
					val := a[i]
					if a[i+2] > val {
						val = a[i+2]
					}
					a[i+1] = val
					// We fixed i and i+2, and i+1 is not a local max.
					// Advancing i to skip unnecessary checks is not strictly required for correctness 
					// because the new value prevents i+2 from being detected as local max,
					// but we can skip i+1 check naturally by loop increment.
				} else {
					// Only a[i] is a local maximum (or a[i+2] is not)
					// Change right neighbor to fix a[i]
					a[i+1] = a[i]
				}
			}
		}

		fmt.Fprintln(writer, ops)
		for i := 0; i < n; i++ {
			if i > 0 {
				fmt.Fprint(writer, " ")
			}
			fmt.Fprint(writer, a[i])
		}
		fmt.Fprintln(writer)
	}
}
```