← Home
For problem statement at 1000-1999/1200-1299/1240-1249/1248/problemB.txt this is a correct solution, but verifier at 1000-1999/1200-1299/1240-1249/1248/verifierB.go ends with All tests passed can you fix the verifier? package main

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

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)
	var n int
	fmt.Fscan(in, &n)
	a := make([]int, n)
	var total int64
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
		total += int64(a[i])
	}
	sort.Ints(a)
	k := (n + 1) / 2
	var s int64
	for i := n - k; i < n; i++ {
		s += int64(a[i])
	}
	ans := s*s + (total-s)*(total-s)
	fmt.Println(ans)
}