#include <bits/stdc++.h>
using namespace std;
int getLargestOutlier(vector<int>& nums) {
map<int,int>mp;
int sum = 0;
for(int i=0;i<nums.size();i++) {
mp[nums[i]]++;
sum+=nums[i];
}
int maxOutlier = INT_MIN;
for(int i=0;i<nums.size();i++) {
int sumWithoutOutlier = sum-nums[i];
if(sumWithoutOutlier%2) continue;
int halfSum = sumWithoutOutlier/2;
mp[nums[i]]--;
if(mp[nums[i]]==0) mp.erase(nums[i]);
if(mp.find(halfSum)!=mp.end()) {
if(maxOutlier<nums[i])
maxOutlier=nums[i];
}
mp[nums[i]]++;
}
return maxOutlier;
}
int main() {
// your code goes here
vector<int>nums={1,1,1,1,1,5,5};
cout<<getLargestOutlier(nums);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgZ2V0TGFyZ2VzdE91dGxpZXIodmVjdG9yPGludD4mIG51bXMpIHsKICAgICAgICBtYXA8aW50LGludD5tcDsKICAgICAgICBpbnQgc3VtID0gMDsKICAgICAgICBmb3IoaW50IGk9MDtpPG51bXMuc2l6ZSgpO2krKykgewogICAgICAgICAgICBtcFtudW1zW2ldXSsrOwogICAgICAgICAgICBzdW0rPW51bXNbaV07CiAgICAgICAgfQogICAgICAgIGludCBtYXhPdXRsaWVyID0gSU5UX01JTjsKICAgICAgICBmb3IoaW50IGk9MDtpPG51bXMuc2l6ZSgpO2krKykgewogICAgICAgICAgICBpbnQgc3VtV2l0aG91dE91dGxpZXIgPSBzdW0tbnVtc1tpXTsKICAgICAgICAgICAgaWYoc3VtV2l0aG91dE91dGxpZXIlMikgY29udGludWU7CiAgICAgICAgICAgIGludCBoYWxmU3VtID0gc3VtV2l0aG91dE91dGxpZXIvMjsKICAgICAgICAgICAgbXBbbnVtc1tpXV0tLTsKICAgICAgICAgICBpZihtcFtudW1zW2ldXT09MCkgbXAuZXJhc2UobnVtc1tpXSk7CiAgICAgICAgICAgIGlmKG1wLmZpbmQoaGFsZlN1bSkhPW1wLmVuZCgpKSB7CiAgICAgICAgICAgICAgICBpZihtYXhPdXRsaWVyPG51bXNbaV0pCiAgICAgICAgICAgICAgICAgbWF4T3V0bGllcj1udW1zW2ldOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICBtcFtudW1zW2ldXSsrOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbWF4T3V0bGllcjsKICAgIH0KCmludCBtYWluKCkgewoJLy8geW91ciBjb2RlIGdvZXMgaGVyZQoJdmVjdG9yPGludD5udW1zPXsxLDEsMSwxLDEsNSw1fTsKCWNvdXQ8PGdldExhcmdlc3RPdXRsaWVyKG51bXMpOwoJcmV0dXJuIDA7Cn0=