Problem:


Score : 500 points

Problem Statement

We have a sequence of N integers: A_1, A_2, \cdots, A_N.

You can perform the following operation between 0 and K times (inclusive):

Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element.

Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.

Constraints

2 \leq N \leq 500

1 \leq A_i \leq 10^6

0 \leq K \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \cdots A_{N-1} A_{N}

Output

Print the maximum possible positive integer that divides every element of A after the operations.

Sample Input 1

2 3
8 20

Sample Output 1

7

7 will divide every element of A if, for example, we perform the following operation:

Choose i = 2, j = 1. A becomes (7, 21).

We cannot reach the situation where 8 or greater integer divides every element of A.

Sample Input 2

2 10
3 5

Sample Output 2

8

Consider performing the following five operations:

Choose i = 2, j = 1. A becomes (2, 6).

Choose i = 2, j = 1. A becomes (1, 7).

Choose i = 2, j = 1. A becomes (0, 8).

Choose i = 2, j = 1. A becomes (-1, 9).

Choose i = 1, j = 2. A becomes (0, 8).

Then, 0 = 8 \times 0 and 8 = 8 \times 1, so 8 divides every element of A. We cannot reach the situation where 9 or greater integer divides every element of A.

Sample Input 3

4 5
10 1 2 22

Sample Output 3

7

Sample Input 4

8 7
1 7 5 6 8 2 6 5

Sample Output 4

5



Sample input:
2 3
8 20


Sample output:
7

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def main():
    n, k = get_li()
    A = get_li()
    ds = make_divisors(sum(A))
    ans = 1
    for d in ds[1:]:
        pdiff = [0] * n
        ndiff = [0] * n
        for i, a in enumerate(A):
            pdiff[i] = a % d
            ndiff[i] = a % d - d
        hoge = list(sorted(zip(pdiff, ndiff)))
        ps = [h[0] for h in hoge]
        ns = [h[1] for h in hoge]
        pacc = list(its.accumulate(ps))
        nacc = list(reversed(list(its.accumulate(reversed(ns)))))
        if min([abs(p + n) for p, n in zip(pacc, nacc)]) <= k * 2:
            ans = d
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def gets(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split(' '))
A = list(map(int,input().split(' ')))

sumA = sum(A)

p = 1
pre_q = sumA + 1
while(p <= sumA):
	q = sumA // p
	if q == pre_q:
		p += 1
		continue
	res = [a % q for a in A]
	res = sum(res)
	if res  <= 2*K:
		print(q)
		exit()
	pre_q = q
	p += 1

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int,input().split())
A = list(map(int, input().split()))
suma = sum(A)
maxsqrt = int(math.sqrt(suma))
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
ans = A[0]
for i in range(1, N):
    ans = gcd(ans,A[i])

for i in range(1, maxsqrt):
    amari = suma % i
    if amari != 0:
        pass
    else:
        sho = suma / i
        shocount = 0
        icount = 0
        for j in range(N):
            shocount += A[j] % sho
            icount +=  A[j] % i


        if shocount < 2 *  K:
            ans = max(sho,ans)
            break
        elif icount < 2 * K:
            ans = max(i, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
from math import sqrt

N, K = map(int, input().split())
A = [int(s) for s in input().split()]
A.sort()
S = sum(A)
c = 0
ist = 0
ans = 0
dl = []
dr = []
for i in range(1, round(sqrt(S)) + 1):
    if S % i != 0:
        continue
    dl.append(i)
    dr.append(S // i)
ds = dr + list(reversed(dl))
final = False
for n in range(N):
    if final:
        break
    if A[n] > K:
        ist = n
        final = True
    else:
        c += A[n]
        K -= A[n]
        A[n] = 0
    for i in ds:
        cnt = 0
        ok = True
        for v in A[ist:]:
            if v >= i:
                break
            cnt += i - v
            if cnt > c + K:
                ok = False
                break
        if ok:
            ans = max(ans, i)
if A[-2] == 0:
    print(S)
    exit()
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

def prime_division(x):
    q = int(math.sqrt(x))
    a = []
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            a.append([i,ex])
    if x>q:
        a.append([x,1])
    return a

def rest(i,k):
    r = i%k
    if r <= k//2:
        return r
    else:
        return k-r

def foo(x):
    b = []
    for y in a:
        b.append(y%x)
    b.sort()
    m = k
    while m>0 and len(b)>0:
        if b[0] < x-b[-1]:
            if m<b[0]:
                return False
            m -= b[0]
            b[-1] -= b[0]
            b = b[1:]
            p = len(b)-1
            while p>0 and b[p-1]>b[p]:
                b[p-1],b[p] = b[p],b[p-1]
        else:
            d = x-b[-1]
            if m<d:
                return False
            m -= d
            b[0] -= d
            b.pop()
            p = 0
            while p<len(b)-1 and b[p]>b[p+1]:
                b[p],b[p+1] = b[p+1],b[p]
    return (len(b)==0)

n,k = inm()
a = inl()
sm = sum(a)
f = prime_division(sm)

facs = [1]
for z in f:
    b = z[0]
    e = z[1]
    newfacs = []
    for x in facs:
        for i in range(e+1):
            newfacs.append(x*(b**i))
    facs = newfacs

facs.sort(reverse=True)
for x in facs:
    if foo(x):
        print(x)
        exit()
print(1)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def main():
    n, k = get_li()
    A = get_li()
    ds = make_divisors(sum(A))
    ans = 1
    for d in ds[1:]:
        print(d)
        pdiff = [0] * n
        ndiff = [0] * n
        for i, a in enumerate(A):
            pdiff[i] = a % d
            ndiff[i] = a % d - d
        hoge = list(sorted(zip(pdiff, ndiff)))
        ps = [h[0] for h in hoge]
        ns = [h[1] for h in hoge]
        pacc = list(its.accumulate(ps))
        nacc = list(reversed(list(its.accumulate(reversed(ns)))))
        print(pacc)
        print(nacc)
        print()
        if min([abs(p + n) for p, n in zip(pacc, nacc)]) <= k * 2:
            ans = d
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def gets(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

sum = 0
for i in range(N):
    sum += A[i]

divisors = []
for i in range(1, int(sum**0.5)+1):
    if sum % i == 0:
        divisors.append(i)
        if i != sum // i:
            divisors.append(sum//i)

divisors.sort(reverse=True)

for d in divisors:
    v = []
    for i in range(N):
        v.append(A[i]%d)
    v.sort(reverse=True)
    vMin = 0
    for i in range(N):
        vMin += v[i]
    abc = 0
    for i in range(N):
        abc += d-v[i]
        vMin = min(vMin-v[i], abc)
    if vMin <= K:
        print(d)
        exit()

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

def divisers(n):
    divs = set([])
    sq = int(math.sqrt(n))
    for i in range(1, sq + 1):
        if n % i == 0:
            divs.add(i)
            divs.add(n//i)
    return list(divs)

l = sorted(divisers(sum(A)), reverse=True)

for val in l:
    sum_val = 0
    for a in A:
        sum_val += a % val
    if sum_val // 2 <= K:
        print(val)
        break

Submission status: Wrong Answer

Solution code:
from math import sqrt
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
div = []
for i in range(1, int(sqrt(s)+1)):
	if s%i == 0:
		if i*i != s:
			div.append(s//i)
		div.append(i)
div.sort(reverse=True)
#print(div)

for d in div:
	b = [x for x in a if x%d != 0]
	if not b:
		print(d)
		break
	b.sort(key=lambda x: x%d)
	y, z = 0, d*len(b)-sum(b)
	res = 10**30
	for x in b:
		y += x
		z -= d-x
		res = min(res, max(y, z))
	if res <= k:
		print(d)
		break

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
S = sum(A)
def check(n):
    for i in range(N):
        if A[i] % n <= K:
            return True
    return False

import math
for i in range(math.floor(math.sqrt(S))+10**5, -1, -1):
    if S % i == 0 and check(i):
        print(i)
        exit(0)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
sum_a = sum(a)
def divisor(n): #約数全列挙
    ans = [1,n]
    i = 2
    while i**2 <= n:
        if n%i == 0:
            ans.append(i)
            if i**2 < n:
                ans.append(n//i)
        i += 1
    ans.sort()
    return ans
anslist = divisor(sum_a)
def solve(x):
    b =[a[i]%x for i in range(n)]
    b.sort()
    count = 0
    i = 0
    j = n-1
    now = 0
    while j > i:
        count += b[i]
        now += b[i]
        i += 1
        if now+b[j]>=x:
            now -= x-b[j]
            j -= 1
    for i in range(n):
        if b[i]%x != 0:
            return False
    if count > k:
        return False
    else:
        return True



ng = len(anslist)
ok = 0
s = 0
while abs(ng-ok)>1:
    middle = (ok+ng)//2
    if(solve(anslist[middle])):
        ok = middle
    else:
        ng = middle
    s += 1


print(anslist[ok])

Submission status: Wrong Answer

Solution code:
import math

N, K = map(int, input().split())
a_list = list(map(int, input().split()))

def decompose(n):
	if n == 1:
		return []
	
	if n % 2 == 0:
		return decompose(n // 2) + [2]
	
	for i in range(3, math.floor(math.sqrt(n)) + 1, 2):
		if n % i == 0:
			return decompose(n // i) + [i]
	return [n]

def check(a_list, p):
	total_m = 0
	total_p = 0
	m_list = []
	p_list = []
	for a in a_list:
		a_f = a - (a % p)
		a_c = a_f + p
		minus = a - a_f
		plus = a_c - a
		if minus > plus:
			total_p += plus
			p_list.append(plus)
		else:
			total_m += minus
			m_list.append(minus)
	return max(total_p, total_m)
	
total = sum(a_list)
checked = set()
for p in [total] + decompose(total):
	if p in checked:
		continue
	checked.add(p)
	if check(a_list, p) <= K:
		print(p);
		exit(0)
print(1)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
sumA = sum(A)

# 約数の全列挙
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort(reverse = True)  # ソート
    return divisors

ansList = divisors(sumA)
ans = 1

for div in ansList :
    posCount = 0
    negCount = 0
    middleCount = 0

    for a in A :
        b = a % div  # 倍数までの距離
        if b < (div - b) :
            negCount += b
        elif b > (div - b) :
            posCount += (div - b)
        else :
            middleCount += b

    if (posCount + negCount + middleCount) <= 2 * K :
        if (posCount - negCount - middleCount) % 2 == 0 :
            ans = div
            break

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N, K = map(int, input().split())
A = list(map(int, input().split()))

def check(g):
  temp = 0
  temp2 = 0
  for i in A:
    temp2 += 1
    if i % g > g // 2:
      temp += abs((i % g) - g)
    else:
      temp -= abs((i % g) - g)
  if temp > K:
    return False
  else:
    if temp2 > K:
      return False
    else:
      return True
#binary_S
def search(l, r):
  m = (l + r) // 2
  if abs(l - r) < 2:
    return m
  if check(m) == True:
    return search(m, r)
  else:
    return search(l, m)
print(search(1, max(A)))

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort(reverse = True)
    return divisors

if __name__ == "__main__":
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    max = A[N-1]
    S = sum(A)
    divs = make_divisors(S)
    ans = 1
    D = len(divs)
    for i in range(D):
        d = divs[i]
        B = [a%d for a in A]
        C = [(d-a%d) for a in A]
        B.sort()
        b = 0
        c = sum(C)
        for i in range(N):
            b += B[i]
            c -= C[i]
            if b >= c :
                break
        if K <= (b+c)//2:
            continue
        else:
            ans = d
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
n,k = map(int,input().split())
a = list(map(int,input().split()))

sum1 = sum(a)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

li = make_divisors(sum1)

ans = 0

for i in li:
    a.sort(key = lambda x: min(x%i,i-x%i))
    count = sum1 // i
    count2 = sum1 // i
    count3 = 0
    count4 = 0
    for j in range(len(a)):
        if j != len(a) - 1:
            if a[j] % i == 0:
                count -= a[j] // i
                count2 -= a[j] // i
            else:
                t = a[j] // i
                if abs(a[j] - i * t) == abs(a[j] - i * (t+1)):
                    if j % 2 == 0:
                        count3 += abs(a[j] - i*t)
                        count4 += abs(a[j] - i*(t+1))
                        count -= t
                        count2 -= t+1
                    else:
                        count3 += abs(a[j] - i*(t+1))
                        count4 += abs(a[j] - i*t)
                        count -= t+1
                        count2 -= t
                elif abs(a[j] - i * t) < abs(a[j] - i * (t+1)):
                    count3 += abs(a[j] - i*t)
                    count4 += abs(a[j] - i*t)
                    count -= t
                    count2 -= t
                else:
                    count3 += abs(a[j] - i * (t+1))
                    count4 += abs(a[j] - i * (t+1))
                    count -= t+1
                    count2 -= t+1
        else:
            count3 += abs(a[j] - count * i)
            count4 += abs(a[j] - count * i)
    if min(count3,count4) // 2 <= k:
        ans = max(ans,i)

print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

List = []
List2 = []
A_sum = sum(A)
for i in range(1,int(A_sum**0.5)):
    if A_sum%i == 0:
        List.append(i)
for j in range(len(List)):
    a = A_sum//List[-1-j]
    if a in List:
        a = 0
    else:
        List2.append(a)

List = List + List2
ans = A_sum
for i in range(len(List)):
    num = 0
    for j in range(N):
        n = abs(List[i]-A[j])
        m = abs(List[i]-A[j]*(-1))
        if n < m:
            num += abs(List[i]-A[j])
        else:
            num += m
    if num//2 <= K:
        ans = List[i]
        
print(ans)

Submission status: Wrong Answer

Solution code:
def cd(num, max):
	cd_list = []
	for i in reversed(range(1,max+1)):
		if num%i==0:
			cd_list.append(i)
	return cd_list

n, k = map(int, input().split())
a = list(map(int, input().split()))
cd_list = cd(sum(a),sum(a)//n)
for num in cd_list:
	rem=0
	for i in a:
		rem += abs(i-num*round(i/num))
	if rem//2<=k:
		print(num)
		break

Submission status: Wrong Answer

Solution code:
[N,K] = list(map(int,input().split()))
A = list(map(int,input().split()))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

SUMA = sum(A)
yaku = make_divisors(SUMA)
yaku.sort(reverse=True)

for yakusu in yaku:
    Amari = []
    for i in range(N):
        X = A[i]%yakusu
        Amari.append(X)
    if max(Amari) < K:
        print(yakusu)
        break

Submission status: Wrong Answer

Solution code:
# from math import gcd
import math
def yakusu(n):
    results = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            results.append(i)
            results.append(n // i)
    return results

# def lcm(a, b):
#     return a * b // gcd(a, b)

N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in yakusu(sum(A)):
    s = sum(map(lambda x: x % i, A))
    # print(s, i)
    if s % i == 0 and s//2 <= K:
        ans = max(ans, i)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import deque


def roundup_div(a, b):
    return (a + b - 1) // b


def moddist(a, mod):
    res1 = a % mod
    res2 = abs(res1 - mod)
    return min(res1, res2), res1 == res2


def can_divide_by(mod, N, K, A):
    sumd = 0
    same = 0
    same_res = 0
    for a in A:
        dist, flg = moddist(a, mod)
        if not flg:
            sumd += dist
        else:
            same += 1
            same_res = dist

    if same > 0:
        if same % 2 == 0:
            same_res * same // 2 + sumd // 2 <= K
        else:
            return False
    else:
        return sumd // 2 <= K


def divisors(x):
    res = []
    for i in range(1, x + 1):
        if x % i == 0:
            res.append(i)
            if i**2 != x:
                res.append(x // i)
        if i ** 2 >= x:
            break
    return sorted(res, reverse=True)


def solve(N: int, K: int, A: "List[int]"):
    suma = sum(A)
    for mod in divisors(suma):
        if suma % mod == 0 and can_divide_by(mod, N, K, A):
            return mod


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    ans = solve(N, K, A)
    if ans is not None:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

goukei = sum(A)
candidate = make_divisors(goukei)
tmp_goukei = 0
operation = 0
answer = 1
for c in candidate:
    mod_c = sorted([a % c for a in A], reverse=True)
    sum_c = sum(mod_c)
    counter = 0
    for a in mod_c:
        sum_c -= 7
        counter += c - a
        if sum_c <= 0:
            break
    # print(c, a, counter)
    if counter <= K:
        answer = c
        break
    else:
        tmp_goukei = 0
        operation = 0
print(answer)

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split()]

A = [int(x) for x in input().split()]

s = sum(A)

split_num = 1
while True:
	if(s%split_num == 0):
		t = s//split_num
		
		v = [0]*N
		v2 = [0]*N
		j=0
		for x in A:
			if x%t < t-(x%t):
				v[j] = x%t
				v2[j] = x%t
			else:
				v[j] = (t-(x%t))
				v2[j] += -(t-(x%t))
			j+=1
			#print(t,v, v2)
		
		rp = 0
		rn = 0
		
		rp_m = 0
		rn_m = 0
		for q in v2:
			if q >0:
				rp += q
				if rp_m < q:
					rp_m = q
			else:
				rn -= q
				if rn_m < -q:
					rn_m = -q
		if rp == rn and sum(v)//2 <= K:
			print(t)
			break
			
		if rp!=rn and max(rp - rp_m, rn - rn_m) <= K:
			print(t)
			break
	split_num += 1

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split()))
A = [int(i) for i in input().split()]

A_sum = sum(A)

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

factors = prime_factors(A_sum)

if min(A) < K:
  print(A_sum)
else:
  print(max(factors))

Submission status: Wrong Answer

Solution code:
x,y = map(int,input().split())
a = list(map(int,input().split()))
for i in range(2,int(sum(a)/2)):
  if y-min(a)>=0 and max(a) +y >= sum(a):
    print(x+y)
    break
  elif y-min(a)>=0 and max(a) +y < sum(a) and sum(a) % i == 0:
    print(int(sum(a)/i))
    break
  else:
    if sum(a) % i == 0 and int(sum(a)/i)<=min(a)+y:
      print(int(sum(a)/i))
      break

Submission status: Wrong Answer

Solution code:
import numpy as np

N,K=(int(x) for x in input().split())
A=[int(x) for x in input().split()]
A=np.array(A)
def solve():
    mx=int((sum(A)+K)/N)
    for i in range(mx):
        num=mx-i
        per=A%num
        su=np.sum(per)
        
        #print(num,per,su)

        tmp=per[np.argmin(np.abs(per-(num/2)))]
        if su%num==0 and tmp<K and num-tmp<K:
            return num
            

        
print(solve())