fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n;
  4. int a[25], cnt[105];
  5. vector <int> b, c;
  6.  
  7. main() {
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(0); cout.tie(0);
  10. freopen("TEST.inp", "r", stdin);
  11. freopen("TEST.out", "w", stdout);
  12. cin >> n;
  13. for (int i = 1; i <= n; i++) {
  14. cin >> a[i];
  15. cnt[a[i]]++;
  16. }
  17.  
  18. for (int i = 100; i >= 2; i -= 2) {
  19. if (cnt[i]) {
  20. while (cnt[i]--) b.push_back(i);
  21. }
  22. }
  23. for (int i = 1; i <= 99; i += 2) {
  24. if (cnt[i]) {
  25. while (cnt[i]--) c.push_back(i);
  26. }
  27. }
  28. int posb = 0;
  29. int posc = 0;
  30. int cnt = 0;
  31. int sum = 0;
  32. while (1) {
  33. if (posb < b.size()) {
  34. sum += b[posb];
  35. cnt++;
  36. posb++;
  37. } else break;
  38. if (posc < c.size()) {
  39. sum -= c[posc];
  40. cnt++;
  41. posc++;
  42. } else break;
  43. if (sum < 0) break;
  44. }
  45.  
  46. cout << cnt << " " << sum << '\n';
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty