Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "MAKESTR"
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- using ll = long long;
- using ld = long double;
- constexpr int N = 1e5 + 5;
- int n, a[N], b[N];
- void Read()
- {
- cin >> n;
- for (int i = 1; i <= n; ++i)
- cin >> a[i];
- }
- void Solve()
- {
- sort(a + 1, a + n + 1);
- for (int i = n; i; --i)
- {
- if (a[i] == 0)
- {
- for (int j = 1; j <= i; ++j)
- b[j] = 0;
- break;
- }
- if (i == 1)
- {
- b[i] = a[i];
- break;
- }
- b[i] = a[i];
- for (int j = 1; j < i; ++j)
- a[j] = min(a[j], a[i] - 1);
- }
- ll ans(0);
- for (int i = 1; i <= n; ++i)
- ans += b[i];
- cout << ans;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement