题解
2025-08-04 08:54:42
发布于:浙江
1阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int max_even = INT_MIN;
int max_odd = INT_MIN;
for (int num : a) {
if (num % 2 == 0) {
if (num > max_even) {
max_even = num;
}
} else {
if (num > max_odd) {
max_odd = num;
}
}
}
if (max_even != INT_MIN && max_odd != INT_MIN) {
cout << max_even + max_odd << endl;
} else {
cout << -1 << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个