Advertisement
Saleh127

Live ar 6855

Jul 30th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. cout.tie(0);
  8.  
  9. int a[200000],c,d,e,i,j,k,l;
  10. while(cin>>c)
  11. {
  12. for(i=0; i<c; i++)
  13. {
  14. cin>>a[i];
  15. }
  16. d=0;
  17. while(1)
  18. {
  19. e=0;
  20. for(i=0; i<c; i++)
  21. {
  22. if(a[i]<0)
  23. {
  24. d++;
  25. e=1;
  26. a[i]=abs(a[i]);
  27. if(i==0)
  28. {
  29. a[c-1]-=a[i];
  30. }
  31. else a[i-1]-=a[i];
  32. if(i==c-1)
  33. {
  34. a[0]-=a[i];
  35. }
  36. else a[i+1]-=a[i];
  37. }
  38. }
  39. if(e==0) break;
  40. }
  41. cout<<d<<endl;
  42. }
  43. return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement