Advertisement
erfanul007

CF B #529

Dec 27th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. vector<int>vt,vt1,vt2;
  6. int n,x,ln,i=0,mx=0,mx1=0,mn=999999,mn1=999999,j,k,k1,k2,t;
  7. cin>>n;
  8. while(n--){
  9. cin>>x;
  10. vt.push_back(x);
  11. if(x>mx){
  12. mx=x;
  13. j=i;
  14. }
  15. if(x<mn){
  16. mn=x;
  17. k=i;
  18. }
  19. i++;
  20. }
  21. vt1=vt;
  22. vt2=vt;
  23.  
  24. vt1.erase(vt1.begin()+j);
  25. ln=vt1.size();
  26. for(i=0;i<ln;i++){
  27. if(vt1[i]>mx1)
  28. mx1=vt1[i];
  29. }
  30. k1=mx1-mn;
  31.  
  32. vt2.erase(vt2.begin()+k);
  33. ln=vt2.size();
  34. for(i=0;i<ln;i++){
  35. if(vt2[i]<mn1)
  36. mn1=vt2[i];
  37. }
  38. k2=mx-mn1;
  39.  
  40. t=k1;
  41. if(k1>k2)
  42. t=k2;
  43. cout<<t<<endl;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement