fork download
  1. // وَمَا تَوْفِيقِي إِلَّا بِاللَّهِ عَلَيْهِ تَوَكَّلْتُ وَإِلَيْهِ أُنِيبُ
  2.  
  3. #include <bits/stdc++.h>
  4. #define T int t;cin>>t;while(t--)
  5. #define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
  6. #define ll long long
  7. #define int long long
  8. #define endl '\n'
  9. using namespace std;
  10.  
  11. void Abady() {
  12. T{
  13. int n; cin >> n;
  14. int arr[n];
  15. int e=0,ans=0;
  16. deque<int> o;
  17. for (int i = 0; i < n; i++) {
  18. cin >> arr[i];
  19. if (arr[i]&1) o.push_back(arr[i]);
  20. else e += arr[i];
  21. }
  22. sort(o.rbegin(),o.rend());
  23. if (o.size()) {
  24. ans += e;
  25. }
  26. while (o.size()) {
  27. ans += o.front();
  28. o.pop_front();
  29. if (o.size()) {
  30. o.pop_back();
  31. }
  32. }
  33. cout << ans << endl;
  34. }
  35. }
  36.  
  37. signed main() {
  38. fast;
  39. Abady();
  40. }
  41.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty