fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. void processTests() {
  6. int t;
  7. if (!(cin >> t)) return;
  8. while (t--) {
  9. int n; cin >> n;
  10. vector<ll> oddVals;
  11. ll sumEvens = 0;
  12.  
  13. for (int i = 0; i < n; ++i) {
  14. ll v; cin >> v;
  15. if (v % 2 == 0) sumEvens += v;
  16. else oddVals.push_back(v);
  17. }
  18.  
  19. sort(oddVals.begin(), oddVals.end(), greater<ll>());
  20.  
  21. ll answer = 0;
  22. if (!oddVals.empty()) answer += sumEvens;
  23.  
  24. int left = 0, right = static_cast<int>(oddVals.size()) - 1;
  25. while (left <= right) {
  26. answer += oddVals[left++];
  27. if (left <= right) {
  28. --right;
  29. }
  30. }
  31.  
  32. cout << answer << '\n';
  33. }
  34. }
  35.  
  36. int main() {
  37. ios::sync_with_stdio(false);
  38. cin.tie(nullptr);
  39.  
  40. processTests();
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty