← Home
For problem statement at 0-999/400-499/480-489/484/problemD.txt this is a correct solution, but verifier at 0-999/400-499/480-489/484/verifierD.go ends with All tests passed can you fix the verifier? package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(reader, &n)

	const MinInt = -1000000000000000000
	dp0 := int64(0)
	dp1 := int64(MinInt)
	dp2 := int64(MinInt)

	for i := 0; i < n; i++ {
		var x int64
		fmt.Fscan(reader, &x)

		nextDp0 := dp0
		if dp1 != MinInt {
			val := dp1 - x
			if val > nextDp0 {
				nextDp0 = val
			}
		}
		if dp2 != MinInt {
			val := dp2 + x
			if val > nextDp0 {
				nextDp0 = val
			}
		}

		nextDp1 := dp1
		val1 := dp0 + x
		if val1 > nextDp1 {
			nextDp1 = val1
		}

		nextDp2 := dp2
		val2 := dp0 - x
		if val2 > nextDp2 {
			nextDp2 = val2
		}

		dp0 = nextDp0
		dp1 = nextDp1
		dp2 = nextDp2
	}

	fmt.Println(dp0)
}