Advertisement
Farjana_akter

Untitled

Dec 28th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. int main()
  7. {
  8. int n,arr[20000],i,j,k,steps=0,a,b,c,d,e,mn,pos;
  9. while(cin>>n)
  10. {
  11. steps=0,mn=1e9,pos=0;
  12. for(i=0; i<n; i++)
  13. cin>>arr[i];
  14. while(1)
  15. {
  16. pos=-1;
  17. mn=1e9;
  18. for(i=0; i<n; i++)
  19. {
  20. if(arr[i]<mn && arr[i]<0)
  21. {
  22. mn=arr[i];
  23. pos=i;
  24. }
  25. }
  26. if(pos==-1)
  27. {
  28. break;
  29. }
  30. arr[pos]*=(-1);
  31. // cout<<"arr[pos] "<<arr[pos]<<endl;
  32. if(pos==n-1)
  33. {
  34. arr[n-2]-=arr[pos];
  35. arr[0]-=arr[pos];
  36. }
  37. else if(pos==0)
  38. {
  39. arr[n-1]-=arr[pos];
  40. arr[1]-=arr[pos];
  41. }
  42. else
  43. {
  44. arr[pos-1]-=arr[pos];
  45. arr[pos+1]-=arr[pos];
  46. }
  47. steps++;
  48. }
  49. cout<<steps<<endl;
  50. }
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement