Language: C++

LL n, k;
LL a[1010];
LL sum = 0;
 
bool cond(LL d){
    vector<LL> v;
    for(int i = 1;i <= n;i++)v.emplace_back(a[i]%d);
    sort(ALL(v));
    vector<LL> rui(n + 1, 0);
    for(int i = 1;i <= n;i++){
        rui[i] = rui[i - 1] + v[i - 1];
    }
    for(int i = 0;i <= n;i++){
        LL a = rui[i];
        LL b = (n - i)*d - (rui[n] - rui[i]);
        //cout << d << " " << a << " " << b << endl; 
        if(a == b && max(a, b) <= k)return true;
    }
    return false;
}
 
int main(){
    cin >> n >> k;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        sum += a[i];
    }
    LL ans = 0;
    for(LL i = 1;i * i <= sum;i++){
        if(sum % i == 0){
            if(cond(i))ans = max(ans, i);
            if(cond(sum/i))ans = max(ans, sum/i);
        }
    }
    cout << ans << endl;
}

Compiler output:
a.cc:1:1: error: 'LL' does not name a type
    1 | LL n, k;
      | ^~
a.cc:2:1: error: 'LL' does not name a type
    2 | LL a[1010];
      | ^~
a.cc:3:1: error: 'LL' does not name a type
    3 | LL sum = 0;
      | ^~
a.cc:5:11: error: 'LL' was not declared in this scope
    5 | bool cond(LL d){
      |           ^~
a.cc: In function 'int main()':
a.cc:23:5: error: 'cin' was not declared in this scope
   23 |     cin >> n >> k;
      |     ^~~
a.cc:23:12: error: 'n' was not declared in this scope
   23 |     cin >> n >> k;
      |            ^
a.cc:23:17: error: 'k' was not declared in this scope
   23 |     cin >> n >> k;
      |                 ^
a.cc:25:16: error: 'a' was not declared in this scope
   25 |         cin >> a[i];
      |                ^
a.cc:26:9: error: 'sum' was not declared in this scope
   26 |         sum += a[i];
      |         ^~~
a.cc:28:5: error: 'LL' was not declared in this scope
   28 |     LL ans = 0;
      |     ^~
a.cc:29:11: error: expected ';' before 'i'
   29 |     for(LL i = 1;i * i <= sum;i++){
      |           ^~
      |           ;
a.cc:29:18: error: 'i' was not declared in this scope
   29 |     for(LL i = 1;i * i <= sum;i++){
      |                  ^
a.cc:29:27: error: 'sum' was not declared in this scope
   29 |     for(LL i = 1;i * i <= sum;i++){
      |                           ^~~
a.cc:31:20: error: 'cond' cannot be used as a function
   31 |             if(cond(i))ans = max(ans, i);
      |                ~~~~^~~
a.cc:31:24: error: 'ans' was not declared in this scope
   31 |             if(cond(i))ans = max(ans, i);
      |                        ^~~
a.cc:31:30: error: 'max' was not declared in this scope
   31 |             if(cond(i))ans = max(ans, i);
      |                              ^~~
a.cc:32:26: error: 'cond' cannot be used as a function
   32 |             if(cond(sum/i))ans = max(ans, sum/i);
      |                          ^
a.cc:32:28: error: 'ans' was not declared in this scope
   32 |             if(cond(sum/i))ans = max(ans, sum/i);
      |                            ^~~
a.cc:32:34: error: 'max' was not declared in this scope
   32 |             if(cond(sum/i))ans = max(ans, sum/i);
      |                                  ^~~
a.cc:35:5: error: 'cout' was not declared in this scope
   35 |     cout << ans << endl;
      |     ^~~~
a.cc:35:13: error: 'ans' was not declared in this scope
   35 |     cout << ans << endl;
      |             ^~~
a.cc:35:20: error: 'endl' was not declared in this scope
   35 |     cout << ans << endl;
      |                    ^~~~