Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- vector<int>vt,vt1,vt2;
- int n,x,ln,i=0,mx=0,mx1=0,mn=999999,mn1=999999,j,k,k1,k2,t;
- cin>>n;
- while(n--){
- cin>>x;
- vt.push_back(x);
- if(x>mx){
- mx=x;
- j=i;
- }
- if(x<mn){
- mn=x;
- k=i;
- }
- i++;
- }
- vt1=vt;
- vt2=vt;
- vt1.erase(vt1.begin()+j);
- ln=vt1.size();
- for(i=0;i<ln;i++){
- if(vt1[i]>mx1)
- mx1=vt1[i];
- }
- k1=mx1-mn;
- vt2.erase(vt2.begin()+k);
- ln=vt2.size();
- for(i=0;i<ln;i++){
- if(vt2[i]<mn1)
- mn1=vt2[i];
- }
- k2=mx-mn1;
- t=k1;
- if(k1>k2)
- t=k2;
- cout<<t<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement