Advertisement
aldaiarov

Untitled

Mar 27th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #define _CRT_DISABLE_PERFCRIT_LOCKS
  2. #include<bits/stdc++.h>
  3.  
  4. #define ll long long int
  5. #define pb push_back
  6. #define ifor for(i=0; i<n; i++)
  7.  
  8. using namespace std;
  9.  
  10. ll INF=1e18;
  11.  
  12. int main()
  13. {
  14.     ios_base::sync_with_stdio(false);
  15.     cin.tie(NULL); cout.tie(NULL);
  16.  
  17.     ll n, i, j, x, y, mindis=INF, kol;
  18.     cin>>n;
  19.     vector < ll > a(n);
  20.     ifor
  21.     {
  22.         cin>>a[i];
  23.     }
  24.     sort(a.begin(), a.end());
  25.     ll dis;
  26.     mindis=abs(a[1]-a[1-1]);
  27.     kol=1;
  28.     for(i=2; i<n; i++)
  29.     {
  30.         dis=abs(a[i]-a[i-1]);
  31.         if(dis==mindis) {kol++; }
  32.         if(dis<mindis) {mindis=dis; kol=1;}
  33.     }
  34.     cout<<mindis<<" "<<kol<<endl;
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement