fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N=1e6+4;
  4. long long a[N],n;
  5. int main()
  6. {
  7. cin>>n;
  8. for(int i=1;i<=n;i++)
  9. {
  10. cin>>a[i];
  11. }
  12. sort(a+1,a+n+1,greater<long long>());
  13. long long s=a[1];
  14. for(int i=2;i<=n;i++)
  15. {
  16. long long t=a[i]-i+1;
  17. if(t>0) s=s+t;
  18. }
  19. cout<<s;
  20. }
  21.  
Success #stdin #stdout 0.01s 5496KB
stdin
Standard input is empty
stdout
Standard output is empty