← Home
For problem statement at 1000-1999/1200-1299/1260-1269/1267/problemG.txt this is a correct solution, but verifier at 1000-1999/1200-1299/1260-1269/1267/verifierG.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, xInt int
	fmt.Fscan(reader, &n, &xInt)
	x := float64(xInt)

	c := make([]int, n)
	sumC := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &c[i])
		sumC += c[i]
	}

	dp := make([][]float64, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]float64, sumC+1)
	}
	dp[0][0] = 1.0

	curSum := 0
	for i := 1; i <= n; i++ {
		ci := c[i-1]
		curSum += ci
		for k := i; k >= 0; k-- {
			for S := curSum; S >= 0; S-- {
				var p1, p2 float64
				if k < i {
					p1 = dp[k][S] * float64(i-k) / float64(i)
				}
				if k > 0 && S >= ci {
					p2 = dp[k-1][S-ci] * float64(k) / float64(i)
				}
				dp[k][S] = p1 + p2
			}
		}
	}

	R0 := 0.0
	for m := 1; m <= n; m++ {
		R0 += x * float64(n+m) / float64(2*m)
	}

	ans := R0
	for k := 1; k <= n; k++ {
		Tk := x * float64(n+k) / 2.0
		W_nk := x * float64(n+k) / float64(2*k)
		for S := 0; S <= sumC; S++ {
			if float64(S) <= Tk {
				prob := dp[k][S]
				if prob > 0 {
					term := float64(S)/float64(k) - W_nk
					ans += prob * term
				}
			}
		}
	}

	fmt.Printf("%.12f\n", ans)
}