← Home
For problem statement at 1000-1999/1400-1499/1420-1429/1420/problemC2.txt this is a correct solution, but verifier at 1000-1999/1400-1499/1420-1429/1420/verifierC2.go ends with output mismatch
expected:
7
11
14
13
13
13
20
18
23
18
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
3
3
14
14
14
13
17
6
5
6
5
18
20
20
20
18
1
4
4
2
2
2
2
2
13
10
16
16
24
24
1
1
1
1
1
1
17
18
23
21
21
24
24
20
26
26
25
25
24
24
1
1
1
7
5
5
21
4
3
3
3
4
3
9
9
8
9
9
8
4
4
4
3
3
4
2
2
2
2
2
1
1
1
1
1
1
10
11
13
12
16
4
3
11
13
13
13
10
4
4
3
3
3
4
4
3
3
3
12
16
4
2
10
9
12
13
5
6
6
5
4
4
10
9
10
8
9
8
7
11
12
12
11
12
20
18
22
22
23
8
9
8
8
11
12
15
14
16
18
3
3
3
4
4
3
3
3
3
3
9
8
2
2
2
2
22
22
25
20
18
15
1
1
1
1
1
1
1
22
22
8
9
8
12
11
13
12
10
17
16
17
20
20
21
21
13
14
13
17
14
1
1
1
1
1
11
3
17
15
17
18
19
19
6
6
6
16
16
21
20
14
16
20
20
16
16
13
7
7
7
9
9
20
20
19
19
27
4
4
4
4
4
6
6
6
11
12
7
1
1
11
12
3
3
3
4
5
9
12
9
7
11
4
4
4
4
4
4
11
10
10
10
3
4
4
3
4
3
2
2
2
2
2
25
24
19
25
15
15
18
25
23
5
14
2
2
2
2
2
14
15
17
4
5
6
2
2
2
19
20
3

got:
7 11 14 13 13
13 20
18 23 18
1 1 1 1 1 1
2 2 2 2 2
2 2 2 2 2
1 1 1 1 1
3 3
14 14 14 13 17
6 5 6 5
18 20 20 20 18
1
4 4
2 2 2 2 2
13 10 16 16
24 24
1 1 1 1 1 1
17 18 23
21 21 24 24
20
26 26 25 25 24 24
1 1 1
7 5 5
21
4 3 3 3 4 3
9 9 8 9 9
8
4 4 4 3 3 4
2 2 2 2 2
1 1 1 1 1 1
10 11 13 12
16
4 3
11
13 13 13 10
4 4 3 3 3
4 4 3 3 3
12 16
4
2
10 9 12 13
5 6 6 5 4 4
10 9 10
8 9 8 7
11 12 12 11 12
20 18 22 22 23
8
9 8 8 11 12
15 14 16 18
3 3 3 4 4
3 3 3 3 3
9 8
2 2 2 2
22 22 25 20
18
15
1 1
1 1 1 1 1
22 22
8 9 8 12 11 13
12 10
17 16 17
20 20 21 21
13 14 13
17
14
1 1 1 1 1
11
3
17 15 17 18 19 19
6 6 6
16 16
21 20 14 16 20 20
16 16 13
7 7 7 9 9
20 20 19 19
27
4 4 4 4 4
6 6 6
11 12
7
1 1
11 12
3 3 3 4
5
9 12 9 7 11
4 4 4 4 4 4
11 10 10 10
3 4 4 3 4 3
2 2 2 2 2
25 24 19 25
15 15 18 25 23
5
14
2 2 2 2 2
14 15 17
4 5 6
2 2 2
19 20
3

exit status 1 can you fix the verifier? package main

import (
	"io"
	"os"
	"strconv"
)

func contrib(a []int64, i int) int64 {
	if i <= 0 || i >= len(a) {
		return 0
	}
	if i == 1 {
		return a[1]
	}
	if a[i] > a[i-1] {
		return a[i] - a[i-1]
	}
	return 0
}

func main() {
	data, _ := io.ReadAll(os.Stdin)
	p := 0
	nextInt := func() int {
		for p < len(data) && data[p] <= ' ' {
			p++
		}
		x := 0
		for p < len(data) && data[p] > ' ' {
			x = x*10 + int(data[p]-'0')
			p++
		}
		return x
	}

	t := nextInt()
	out := make([]byte, 0, 1<<22)

	for ; t > 0; t-- {
		n := nextInt()
		q := nextInt()

		a := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			a[i] = int64(nextInt())
		}

		var ans int64 = a[1]
		for i := 2; i <= n; i++ {
			if a[i] > a[i-1] {
				ans += a[i] - a[i-1]
			}
		}

		out = strconv.AppendInt(out, ans, 10)

		for ; q > 0; q-- {
			l := nextInt()
			r := nextInt()

			var pos [5]int
			cnt := 0
			add := func(x int) {
				if x < 1 || x > n {
					return
				}
				for i := 0; i < cnt; i++ {
					if pos[i] == x {
						return
					}
				}
				pos[cnt] = x
				cnt++
			}

			add(1)
			add(l)
			add(l + 1)
			add(r)
			add(r + 1)

			for i := 0; i < cnt; i++ {
				ans -= contrib(a, pos[i])
			}

			a[l], a[r] = a[r], a[l]

			for i := 0; i < cnt; i++ {
				ans += contrib(a, pos[i])
			}

			out = append(out, ' ')
			out = strconv.AppendInt(out, ans, 10)
		}

		out = append(out, '\n')
	}

	os.Stdout.Write(out)
}