Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<algorithm>
- #define long long long
- #define nln '\n'
- using namespace std;
- int main()
- {
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- //freopen("ranking.inp", "r", stdin);
- long n;
- cin >> n;
- vector<long> a(n);
- for (auto &i : a)
- cin >> i;
- sort(a.rbegin(), a.rend());
- vector<long> b(n+1, 0), c(n+1, 0);
- long j = 0;
- for (auto i : a)
- if (i != b[j]){
- ++j;
- b[j] = i;
- ++c[j];
- }
- else{
- ++c[j];
- }
- long res = 0;
- for (long k = 1; k <= j; ++k)
- res += k*c[k];
- cout << res << nln;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment