Yes it is possible
#include<bits/stdc++.h>
using namespace std;
long long solve(vector<int>&vec,int idx,int dp[]){
if(idx>=vec.size())return 0;
if(dp[idx]!=-1)return dp[idx];
long long a=-1e12,b=-1e12;
if(vec[idx]%2==0)a=vec[idx]+solve(vec,idx+1,dp);
b=solve(vec,idx+1,dp);
return dp[idx]=max(a,b);
}
int main(){
int n;
cin>>n;
int arr[n+1];
for(int i=0;i<n;++i)cin>>arr[i];
vector<int>vec;
priority_queue<int>pq;
for(int i=0;i<n;++i){
if(arr[i]%2)pq.push(arr[i]);
else vec.push_back(arr[i]);
}
while(!pq.empty()){
int x=pq.top();
pq.pop();
if(!pq.empty()){
int y=pq.top();
pq.pop();
vec.push_back(x+y);
}
}
int ans=INT_MIN;
int dp[vec.size()+1];
memset(dp,-1,sizeof dp);
cout<<solve(vec,0,dp);
// cout<<ans<<endl;
}
Yes it is possible
#include<bits/stdc++.h>
using namespace std;
long long solve(vector<int>&vec,int idx,int dp[]){
if(idx>=vec.size())return 0;
if(dp[idx]!=-1)return dp[idx];
long long a=-1e12,b=-1e12;
if(vec[idx]%2==0)a=vec[idx]+solve(vec,idx+1,dp);
b=solve(vec,idx+1,dp);
return dp[idx]=max(a,b);
}
int main(){
int n;
cin>>n;
int arr[n+1];
for(int i=0;i<n;++i)cin>>arr[i];
vector<int>vec;
priority_queue<int>pq;
for(int i=0;i<n;++i){
if(arr[i]%2)pq.push(arr[i]);
else vec.push_back(arr[i]);
}
while(!pq.empty()){
int x=pq.top();
pq.pop();
if(!pq.empty()){
int y=pq.top();
pq.pop();
vec.push_back(x+y);
}
}
int ans=INT_MIN;
int dp[vec.size()+1];
memset(dp,-1,sizeof dp);
cout<<solve(vec,0,dp);
// cout<<ans<<endl;
}