C++代码
2026-10-03 14:31:13
发布于:湖南
0阅读
0回复
0点赞
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<long long> a(n);
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
sort(a.begin(), a.end());
long long b = 1000000000000000010;
long long x, y;
for( int i = 1; i < n; i++ )
{
long long d = a[i] - a[i-1];
if( d < b )
{
b = d;
x = a[i-1];
y = a[i];
}
else if( d == b )
{
if( a[i-1] < x )
{
x = a[i-1];
y = a[i];
}
}
}
cout << b << endl << x << " " << y << endl;
return 0;
}
这里空空如也






有帮助,赞一个