fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int v[1005];
  5.  
  6. int main () {
  7. ios :: sync_with_stdio(0);
  8. int n, k;
  9. cin >> n >> k;
  10. int ans = 0;
  11. for(int i = 1; i <= n; i++) {
  12. int a;
  13. cin >> a;
  14. v[a] += 1;
  15. }
  16. int x;
  17. n % 2 ? x = (n / 2) + 1 : x = n / 2;
  18. for(int i = 1; i <= k && x > 0; i++) {
  19. ans += min(v[i] / 2, x) * 2;
  20. x -= min(v[i] / 2, x);
  21. v[i] % 2 ? v[i] = 1 : v[i] = 0;
  22. }
  23. if(x) {
  24. for(int i = 1; i <= k && x > 0; i++) {
  25. if(v[i]) {
  26. x--;
  27. ans++;
  28. }
  29. }
  30. }
  31. cout << ans;
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty