fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,l=100000,h=0;
  4. int A[100001];
  5. int main() {
  6. cin>>n;
  7. for(int q=0;q<n;q=q+1){
  8. cin>>A[q];
  9. }
  10. for(int q=n-1;q>=0;q=q-1){
  11. if(A[q]<l){
  12. l=A[q];
  13. }
  14. if(A[q]>h){
  15. h=A[q];
  16. }
  17. }
  18. cout<<h-l;
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 5276KB
stdin
5
5 4 3 2 1
stdout
4