Language: C++

#include <bits/stdc++.h>
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=n1;i<(int)(n2);i++)
using namespace std;
typedef long long ll;

signed main()
{
	int N, M;
	cin >> N;
	cin >> M;

	vector<int> A(N);
	vector<double> logA(N);
	Rep(i, N){
		cin >> A[i];
		logA[i] = log2(A[i]);
	}

	sort(A.begin(), A.end(), greater<int>());
	sort(logA.begin(), logA.end(), greater<int>());

	int check = [&](int rank){
		if(rank == N){
			Rep(i, rank-1){
				logA[i] -= M / rank;
			}
			if(M % rank != 0){
				Rep(i, M % rank - 1){
					logA[i]--;
				}
			}
			return 0;
		}
		int logAdiff = logA[rank] - logA[rank-1];
		if(logAdiff*rank <= M-rank){
			Rep(i, rank-1){
				logA[i] -= logAdiff;
				M -= logAdiff;
			}
			if(rank < M){
				rank++;
				return rank;
			}else{
				Rep(i, M-1){
					logA[i]--;
				}
				return 0;
			}
		}else{
			Rep(i, rank-1){
				logA[i] -= M / rank;
			}
			if(M % rank != 0){
				Rep(i, M % rank - 1){
					logA[i]--;
				}
			}
			return 0;
		}
	};

	int rank = 1;
	while(rank != 0){
		rank = check(rank);
	}

	long long sum = 0;
	Rep(i, N){
		sum += pow(2, logA[i]);
	}

	cout << sum;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:21: error: cannot convert 'main()::<lambda(int)>' to 'int' in initialization
   23 |         int check = [&](int rank){
      |                     ^~~~~~~~~~~~~~
      |                     |
      |                     main()::<lambda(int)>
   24 |                 if(rank == N){
      |                 ~~~~~~~~~~~~~~
   25 |                         Rep(i, rank-1){
      |                         ~~~~~~~~~~~~~~~
   26 |                                 logA[i] -= M / rank;
      |                                 ~~~~~~~~~~~~~~~~~~~~
   27 |                         }
      |                         ~
   28 |                         if(M % rank != 0){
      |                         ~~~~~~~~~~~~~~~~~~
   29 |                                 Rep(i, M % rank - 1){
      |                                 ~~~~~~~~~~~~~~~~~~~~~
   30 |                                         logA[i]--;
      |                                         ~~~~~~~~~~
   31 |                                 }
      |                                 ~
   32 |                         }
      |                         ~
   33 |                         return 0;
      |                         ~~~~~~~~~
   34 |                 }
      |                 ~    
   35 |                 int logAdiff = logA[rank] - logA[rank-1];
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   36 |                 if(logAdiff*rank <= M-rank){
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |                         Rep(i, rank-1){
      |                         ~~~~~~~~~~~~~~~
   38 |                                 logA[i] -= logAdiff;
      |                                 ~~~~~~~~~~~~~~~~~~~~
   39 |                                 M -= logAdiff;
      |                                 ~~~~~~~~~~~~~~
   40 |                         }
      |                         ~
   41 |                         if(rank < M){
      |                         ~~~~~~~~~~~~~
   42 |                                 rank++;
      |                                 ~~~~~~~
   43 |                                 return rank;
      |                                 ~~~~~~~~~~~~
   44 |                         }else{
      |                         ~~~~~~
   45 |                                 Rep(i, M-1){
      |                                 ~~~~~~~~~~~~
   46 |                                         logA[i]--;
      |                                         ~~~~~~~~~~
   47 |                                 }
      |                                 ~
   48 |                                 return 0;
      |                                 ~~~~~~~~~
   49 |                         }
      |                         ~
   50 |                 }else{
      |                 ~~~~~~
   51 |                         Rep(i, rank-1){
      |                         ~~~~~~~~~~~~~~~
   52 |                                 logA[i] -= M / rank;
      |                                 ~~~~~~~~~~~~~~~~~~~~
   53 |                         }
      |                         ~
   54 |                         if(M % rank != 0){
      |                         ~~~~~~~~~~~~~~~~~~
   55 |                                 Rep(i, M % rank - 1){
      |                                 ~~~~~~~~~~~~~~~~~~~~~
   56 |                                         logA[i]--;
      |                                         ~~~~~~~~~~
   57 |                                 }
      |                                 ~
   58 |                         }
      |                         ~
   59 |                         return 0;
      |                         ~~~~~~~~~
   60 |                 }
      |                 ~    
   61 |         };
      |         ~            
a.cc:65:29: error: 'check' cannot be used as a function
   65 |                 rank = check(rank);
      |                        ~~~~~^~~~~~