Saleh127

Untitled

May 7th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main()
  5. {
  6. ll n,a[10000],c,d,e,f,i,j,k,lo,ma;
  7. cin>>n;
  8. for(i=1;i<=n;i++)
  9. {
  10. cin>>a[i];
  11. }
  12. lo=a[1];
  13. ma=a[1];
  14. c=1;
  15. d=1;
  16. for(i=1;i<=n;i++)
  17. {
  18. if(a[i]<=lo)
  19. {
  20. lo=a[i];
  21. c=i;
  22. }
  23. if(a[i]>ma)
  24. {
  25. ma=a[i];
  26. d=i;
  27. }
  28. }
  29. if(d>c)
  30. {
  31. e=(d-1)+(n-c)-1;
  32. if(e<0) e=0;
  33. printf("%lld\n",e);
  34. }
  35. else
  36. {
  37. e=(d-1)+(n-c);
  38. if(e<0) e=0;
  39. printf("%lld\n",e);
  40. }
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment