← Home
For problem statement at 1000-1999/1900-1999/1990-1999/1998/problemE2.txt this is a correct solution, but verifier at 1000-1999/1900-1999/1990-1999/1998/verifierE2.go ends with test 1 (sample) failed: test 1: position 5 mismatch: expected 3 got 2
input:
3
5 1
1 2 3 2 1
7 1
4 5 1 2 1 4 5
11 1
1 2 3 1 1 9 3 2 4 1 3
reference:
1 1 2 2 3
1 1 1 1 1 3 4
1 1 2 2 2 1 1 1 3 3 4
output:
1 1 2 2 2
1 1 1 1 1 3 4
1 1 2 2 2 1 1 1 3 3 4
exit status 1 can you fix the verifier? package main

import (
	"os"
	"strconv"
)

type Component struct {
	s  int64
	rR int64
	rL int64
	w  int
}

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

func main() {
	buf, _ := os.ReadFile("/dev/stdin")
	pos := 0

	nextInt := func() int {
		for pos < len(buf) && buf[pos] <= ' ' {
			pos++
		}
		if pos >= len(buf) {
			return 0
		}
		res := 0
		for pos < len(buf) && buf[pos] > ' ' {
			res = res*10 + int(buf[pos]-'0')
			pos++
		}
		return res
	}

	nextInt64 := func() int64 {
		for pos < len(buf) && buf[pos] <= ' ' {
			pos++
		}
		if pos >= len(buf) {
			return 0
		}
		res := int64(0)
		for pos < len(buf) && buf[pos] > ' ' {
			res = res*10 + int64(buf[pos]-'0')
			pos++
		}
		return res
	}

	t := nextInt()
	if t == 0 {
		return
	}

	out := make([]byte, 0, 1024*1024*10)

	for tc := 0; tc < t; tc++ {
		n := nextInt()
		x := nextInt()
		_ = x 

		stack := make([]Component, 0, n)

		for i := 0; i < n; i++ {
			val := nextInt64()
			C := Component{s: val, rR: val, rL: val, w: 1}

			for len(stack) > 0 {
				top := stack[len(stack)-1]
				if top.s < C.rL {
					stack = stack[:len(stack)-1]
					C.rR = max(C.rR, top.rR-C.s)
					C.rL = max(top.rL, C.rL-top.s)
					C.s = top.s + C.s
				} else if C.s >= top.rR {
					stack = stack[:len(stack)-1]
					C.w += top.w
					C.rR = max(C.rR, top.rR-C.s)
					C.rL = max(top.rL, C.rL-top.s)
					C.s = top.s + C.s
				} else {
					break
				}
			}
			stack = append(stack, C)
			out = strconv.AppendInt(out, int64(stack[0].w), 10)
			out = append(out, ' ')
		}
		if len(out) > 0 {
			out[len(out)-1] = '\n'
		}
	}
	os.Stdout.Write(out)
}