Submission

Status:
PPPPPPPPPP

Score: 100

User: meme_boi2

Problemset: วิศวกรรมข้อมูล

Language: cpp

Time: 0.003 second

Submitted On: 2024-12-09 09:21:17

/* 
TASK: data eng 
LANG: C++ 
AUTHOR: CCSleep Broke me  
CENTER: SUT 
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
string tobin(int n){
	string txt = "";
	if(n == 0) return "0";
	while(n != 0){
		txt = to_string(n%2) + txt;
		n /= 2;
	}
	return txt;
}
bool comp(int a, int b){
	string t1 = tobin(a), t2 = tobin(b);
	return t1 + t2 > t2 + t1;
}
signed main(){
	cin.tie(nullptr)->sync_with_stdio(0);
	int n; string txt;
	vector <int> mat;
	cin >> n;
	while(n--){
		int c;
		cin>> c;
		mat.push_back(c);
	}
	sort(mat.begin(),mat.end(), comp);
	if(mat.size() > 2)txt =  tobin(mat[0]) + tobin(mat[1]) + tobin(mat[2]);
	else if(mat.size() == 2)txt = tobin(mat[0]) + tobin(mat[1]);
	else txt = tobin(mat[0]);
	//cout << txt[0] << '\n';
	int num = 0;
	for(int i = 0; i < txt.length(); i++){
		num += (txt[txt.length()-i-1]-'0')*pow(2, i);
	}
	cout << num;
}