Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6. #include <sstream>
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <stack>
  10. #include <queue>
  11. #include <cmath>
  12. #include <iomanip>
  13. //#include <bits/stdc++.h>
  14. using namespace std;
  15. typedef long long ll;
  16. const ll INF = (1 << 30);
  17. const ll inf = (1LL << 60LL);
  18. const ll maxn = 3e5 + 5;
  19.  
  20. int main()
  21. {
  22. vector<int>vect;
  23. int n;
  24. cin>>n;
  25. int a[n + 50];
  26. for(int i=0;i<n;i++)
  27. {
  28. cin>>a[i];
  29. }
  30. int p=a[0];
  31. for(int i=1;i<n;i++)
  32. {
  33. if(a[i]>=p)
  34. {
  35. vect.push_back(a[i]);
  36. }
  37. }
  38. int k=0;
  39.  
  40. if((int)vect.size() > 0){
  41. sort(vect.begin(),vect.end());
  42.  
  43. int maks=vect[((int)vect.size()-1)];
  44. int j=(int)vect.size()-1;
  45. //cout<<"tuka"<<p<<endl;
  46. while(maks>=p)
  47. {
  48. vect[j]=vect[j]-1;
  49. ++p;
  50. sort(vect.begin(),vect.end());
  51. ++k;
  52. maks=vect[((int)vect.size()-1)];
  53. }
  54. }
  55.  
  56. cout<<k<<endl;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement