Problem: 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.

Submission attempts (in order):
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

def checker(A,k):
    if sum(A[sum(A) // d:]) <= k:
        return True
    return False

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

for d in make_divisors(sum(A)):
    buf = []
    for a in A:
        buf.append(a%d)
    
    if checker(buf,k):
        print(d)
        break

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

def checker(A,k):
    if sum(A[sum(A) // d:]) <= k:
        return True
    return False

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

for d in make_divisors(sum(A)):
    buf = []
    if d == 1:
        print(d)
        break
    else:
        for a in A:
            buf.append(a%d)
        
        if checker(buf,k):
            print(d)
            break

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

def checker(A,k):
    if sum(costs[sum(A) // d:]) <= k:
        return True
    return False

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

for d in make_divisors(sum(A)):
    buf = []
    if d == 1:
        print(d)
        break
    else:
        for a in A:
            buf.append(a%d)
        print(buf)
        if checker(buf,k):
            print(d)
            break

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

def checker(A,k):
    if sum(A[sum(A) // d:]) <= k:
        return True
    return False

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

for d in make_divisors(sum(A)):
    buf = []
    if d == 1:
        print(d)
        break
    else:
        for a in A:
            buf.append(a%d)
        print(buf)
        if checker(buf,k):
            print(d)
            break

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

def checker(A,k):
    if sum(sorted(A)[:-1]) <= k:
        return True
    return False

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

for d in make_divisors(sum(A)):
    buf = []
    buf2 = []
    if d == 1:
        print(d)
        break
    else:
        for a in A:
            buf.append(a%d)
        
        if checker(buf.sort(reverse=True),k):
            print(d)
            break

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

def checker(A,k):
    A.sort(reverse=True)
    if sum(A[sum(A) // d:]) <= k:
        return True
    return False

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

for d in make_divisors(sum(A)):
    buf = []
    for a in A:
        buf.append(a%d)
    
    if checker(buf,k):
        print(d)
        break

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Accepted