Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
870 B
1
Indexable
Never
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int cmp(int x,int y)
{
    return x<y;
}
int main() {
   vector<int> arr,temp;
   int n,dis,x;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        arr.push_back(x);
    }
    
    sort(arr.begin(),arr.end(),cmp);
    
    dis=arr[1]-arr[0];
    
    for(int i=2;i<n;i++)
        if(dis>(arr[i]-arr[i-1]))
        {
            dis=arr[i]-arr[i-1];
            temp.clear();
            temp.push_back(arr[i-1]);
            temp.push_back(arr[i]);
        }
        else  if(dis==(arr[i]-arr[i-1]))
        {
            temp.push_back(arr[i-1]);
            temp.push_back(arr[i]);
        }
            
    for(int i=0;i<temp.size();i++)
        cout<<temp[i]<<" ";
    
       
    return 0;
}