这个题目一开始想的太复杂了
class Solution {
public:
int maxmiumScore(vector<int>& cards, int cnt) {
sort(cards.begin(), cards.end(), greater<int>());
int now = 0;
int smji = 0x7fffffff, smou = 0x7fffffff;
for (int i = 0; i < cards.size(); i++) {
if (i < cnt) {
now += cards[i];
if (cards[i] & 1) {
smji = min(smji, cards[i]);
}
else {
smou = min(smou, cards[i]);
}
}
}
if (now % 2 == 0) return now;
int a=0, b=0;
for (int i = cnt; i < cards.size(); i++) {
if (cards[i] & 1) {
if (smou != 0x7fffffff) {
a = max(now - smou + cards[i],a);
}
}
else {
if (smji != 0x7fffffff) {
b = max(b, now - smji + cards[i], b);
}
}
}
return max(a, b);
}
};