fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n; cin >> n;
  6. vector<int> a(n);
  7. for(int i=0;i<n;i++) cin >> a[i];
  8. if(n == 2){
  9. cout << "0";
  10. return 0;
  11. }
  12. sort(a.begin(),a.end());
  13. cout << min(a[n-1]-a[1],a[n-2]-a[0]);
  14. return 0;
  15. }
Success #stdin #stdout 0.01s 5280KB
stdin
2
1 100000
stdout
Standard output is empty