Iamtui1010

ranking.cpp

Aug 12th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4.  
  5. #define long long long
  6. #define nln '\n'
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. cin.tie(0)->sync_with_stdio(0);
  13. cout.tie(0)->sync_with_stdio(0);
  14. //freopen("ranking.inp", "r", stdin);
  15. long n;
  16. cin >> n;
  17. vector<long> a(n);
  18. for (auto &i : a)
  19. cin >> i;
  20. sort(a.rbegin(), a.rend());
  21. vector<long> b(n+1, 0), c(n+1, 0);
  22. long j = 0;
  23. for (auto i : a)
  24. if (i != b[j]){
  25. ++j;
  26. b[j] = i;
  27. ++c[j];
  28. }
  29. else{
  30. ++c[j];
  31. }
  32. long res = 0;
  33. for (long k = 1; k <= j; ++k)
  34. res += k*c[k];
  35. cout << res << nln;
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment