Cardboard for Pictures
Mircea has $$$n$$$ pictures. The $$$i$$$-th picture is a square with a side length of $$$s_i$$$ centimeters. He mounted each picture on a square piece of cardboard so that each picture has a border of $$$w$$$ centimeters of cardboard on all sides. In total, he used $$$c$$$ square centimeters of cardboard. Given the picture sizes and the value $$$c$$$, can you find the value of $$$w$$$?  A picture of the first test case. Here $$$c = 50 = 5^2 + 4^2 + 3^2$$$, so $$$w=1$$$ is the answer. Please note that the piece of cardboard goes behind each picture, not just the border.
The first test case is explained in the statement.For the second test case, the chosen $$$w$$$ was $$$2$$$, thus the only cardboard covers an area of $$$c = (2 \cdot 2 + 6)^2 = 10^2 = 100$$$ squared centimeters.For the third test case, the chosen $$$w$$$ was $$$4$$$, which obtains the covered area $$$c = (2 \cdot 4 + 2)^2 \times 5 = 10^2 \times 5 = 100 \times 5 = 500$$$ squared centimeters.
The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases.The first line of each test case contains two positive integers $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) and $$$c$$$ ($$$1 \leq c \leq 10^{18}$$$) — the number of paintings, and the amount of used square centimeters of cardboard.The second line of each test case contains $$$n$$$ space-separated integers $$$s_i$$$ ($$$1 \leq s_i \leq 10^4$$$) — the sizes of the paintings.The sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.Additional constraint on the input: Such an integer $$$w$$$ exists for each test case.Please note, that some of the input for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
For each test case, output a single integer — the value of $$$w$$$ ($$$w \geq 1$$$) which was used to use exactly $$$c$$$ squared centimeters of cardboard.
import math

def testcase():
    (n, c) = map(int, input().split())
    sum = sum2 = 0
    values = input().split()
    for si in values:
        si = int(si)
        sum += si
        sum2 += si * si
    ans = (-4 * sum + math.sqrt(16 * sum * sum - 16 * n * (sum2 - c))) / (8 * n)
    print(int(ans))
t = int(input())
for _ in range(t):
    testcase()
from math import isqrt
MOD = 1000000007

def main():
    testCases = int(input())
    for testCase in range(1, testCases + 1):
        str = input().split(' ')
        n = int(str[0])
        c = int(str[1])
        ss = 0
        s = 0
        str = input().split(' ')
        for i in range(n):
            num = int(str[i])
            ss += num * num
            s += num
        C = ss - c
        B = 4 * s
        A = 4 * n
        b1 = 4 * A * C
        res = B * B - b1
        sq = isqrt(res)
        ans = (sq - B) // (2 * A)
        print(ans)
if __name__ == '__main__':
    main()
from math import sqrt
for _ in range(int(input())):
    (n, c) = map(int, input().split())
    ps = list(map(int, input().split()))
    sp = sum(ps)
    sp2 = sum((p * p for p in ps))
    w = (int(sqrt(sp ** 2 - n * (sp2 - c))) - sp) // (2 * n)
    print(w)