← Home
For problem statement at 1000-1999/1200-1299/1200-1209/1203/problemE.txt this is a correct solution, but verifier at 1000-1999/1200-1299/1200-1209/1203/verifierE.go ends with All tests passed can you fix the verifier? package main

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

type FastScanner struct {
	r *bufio.Reader
}

func NewFastScanner() *FastScanner {
	return &FastScanner{r: bufio.NewReaderSize(os.Stdin, 1<<20)}
}

func (fs *FastScanner) NextInt() int {
	sign, val := 1, 0
	c, _ := fs.r.ReadByte()
	for (c < '0' || c > '9') && c != '-' {
		c, _ = fs.r.ReadByte()
	}
	if c == '-' {
		sign = -1
		c, _ = fs.r.ReadByte()
	}
	for c >= '0' && c <= '9' {
		val = val*10 + int(c-'0')
		c, _ = fs.r.ReadByte()
	}
	fs.r.UnreadByte()
	return sign * val
}

func main() {
	fs := NewFastScanner()
	n := fs.NextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = fs.NextInt()
	}

	sort.Ints(a)

	used := make([]bool, 150005)
	ans := 0

	for _, x := range a {
		if x > 1 && !used[x-1] {
			used[x-1] = true
			ans++
		} else if !used[x] {
			used[x] = true
			ans++
		} else if !used[x+1] {
			used[x+1] = true
			ans++
		}
	}

	fmt.Println(ans)
}