Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: mmpk

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

Language: cpp

Time: 0.003 second

Submitted On: 2025-10-02 15:16:43

#include<bits/stdc++.h>
using namespace std;
int a[4];
int n;
int mx=0;

string tb(int x){
  if(x==0){
    return "0";
  }
  string s ="";
  while(x>0){
    s=char('0'+(x%2))+s;
    x/=2;
  }
  return s;
}
int d(string s){
  int sum=0;
  int p=1;
  reverse (s.begin(),s.end());
  for(int i=0;i<s.size();i++){
 	 sum+=(s[i]-'0')*p;
    p=p*2;  
  }
 return sum;     
}

 
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  string s="";
  for(int j=0;j<n;j++){
    s=s+tb(a[j]);
	}
 mx=max(mx,d(s)); 
  sort(a+0,a+n);
  //sort(a+1,a+n+1);
   s="";
  for(int j=0;j<n;j++){
    s=s+tb(a[j]);
	}
 mx=max(mx,d(s));
  
   sort(a+0,a+n,greater<int>());
   s="";
  for(int j=0;j<n;j++){
    s=s+tb(a[j]);
	}
 mx=max(mx,d(s));
  
  cout<<mx;
}