fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int n;
  7. cin>>n;
  8. bool bl = false;
  9. vector<long long int>v;
  10. for(int i =1;i<=n;i++){
  11. int a;
  12. cin>>a;
  13. v.push_back(a);
  14. // if(a==1)bl=true;
  15. }
  16.  
  17. sort(v.begin(),v.end());
  18.  
  19. cout<<abs(v[0]-v[1])<<' '<<abs(v[0]-v[n-1])<<endl;
  20.  
  21. for(int i = 1 ; i<v.size()-1;i++){
  22. int mn = min(v[i]-v[i-1],v[i+1]-v[i]);
  23. int mx= max(v[n-1]-v[i],v[i]-v[0]);
  24. cout<<mn<<' '<<mx<<endl;
  25. }
  26.  
  27. cout<<v[n-1]-v[n-2]<<' '<<v[n-1]-v[0]<<endl;
  28.  
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 5556KB
stdin
4
-5 -2 2 7
stdout
3 12
3 9
4 7
5 12