CF2148D 题解
传送门:洛谷 CF2148D Destruction of the Dandelion Fields | Codeforces D. Destruction of the Dandelion Fields
更佳的阅读体验:CF2148D 题解
简要题意:有
首先可以确定的是,只要有
接下来考虑如何安排
记奇数个数为
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
int t, n;
ll a, ans;
basic_string<ll> odd, even;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
for (cin >> t; t; --t) {
ans = 0;
odd.clear(), even.clear();
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a;
if (a & 1) odd += a;
else even += a;
} if (!odd.size()) {
cout << "0\n";
continue;
} for (auto p : even) ans += p;
sort(odd.begin(), odd.end(), greater<>());
for (int i = 0; i < (odd.size() + 1) / 2; ++i) ans += odd[i];
cout << ans << '\n';
} return 0;
}