fork download
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. const int N = int(1e5) + 1;
  6.  
  7. int n, k;
  8. int ai;
  9. int a[N];
  10. int p[N];
  11. long long ans;
  12.  
  13. bool comp(int x, int y)
  14. {
  15. return a[x] < a[y];
  16. }
  17.  
  18. int main()
  19. {
  20. freopen("input.txt", "rt", stdin);
  21. freopen("output.txt", "wt", stdout);
  22.  
  23. scanf("%d%d", &n, &k);
  24.  
  25. for (int i = 0; i < n; i++)
  26. {
  27. scanf("%d", &ai);
  28.  
  29. a[ai - 1]++;
  30. }
  31.  
  32. for (int i = 0; i < k; i++)
  33. p[i] = i;
  34.  
  35. std::sort(p, p + k, comp);
  36.  
  37. int sum = n;
  38.  
  39. for (int i = 0; i < k; i++)
  40. {
  41. ans += sum;
  42. sum -= a[p[i]];
  43. }
  44.  
  45. std::cout << ans;
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 16024KB
stdin
Standard input is empty
stdout
Standard output is empty