Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. // Created by Никита on 11.10.17.
  2. // Copyright © 2017 Никита. All rights reserved.
  3. //
  4.  
  5. #include <iostream>
  6. using namespace std;
  7. int main(int argc, const char * argv[])
  8. {
  9. int i, n, x;
  10. int a[100000];
  11. x = 0;
  12. cin >> n;
  13.  
  14. for (i=0; i<n; i++)
  15. {
  16. cin >> a[i];
  17. }
  18. i=n-1;
  19. int r=n-1;
  20. while (i>0)
  21. {
  22. while (i > 0 && a[n-1]==a[i-1]) {r--; i--;};
  23. if ((x + (n - r)) > a[n-1] - 1) break;
  24. x+=n-r;
  25. a[n-1]--;
  26. }
  27. if (i==0)
  28. cout << (x+a[n-1]*n + n)/(n+1);
  29. else if (a[n-1]>x)
  30. cout << a[n-1];
  31. else
  32. cout << x;
  33.  
  34. return 0;
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement