CodeForces 792A之New Bus Route

来源:互联网 发布:手机网页编辑软件 编辑:程序博客网 时间:2024/05/16 10:28

Description

There are n cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers a1, a2, ..., an. All coordinates are pairwise distinct.

It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates.

It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs.

Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance.

Input

The first line contains one integer number n (2 ≤ n ≤ 2·105).

The second line contains n integer numbers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). All numbers ai are pairwise distinct.

Output

Print two integer numbers — the minimal distance and the quantity of pairs with this distance.

Sample Input

Input
46 -3 0 4
Output
2 1
Input
3-2 0 2
Output

2 2


题意:给你n个数,问你任意两个之差的绝对值最小为多少,这样的组合有多少个?


AC代码如下:

#include<iostream>#include<algorithm>#include <cstdio>#include <cstring>using namespace std;const int maxn=2*1e5+100;typedef long long llint;llint n;llint mai[maxn],num;llint a[maxn];int main(){    while(cin>>n)    {        memset(mai,0,sizeof(mai));        memset(a,0,sizeof(a));        num=0;        for(int i=0;i<n;i++) cin>>a[i];        sort(a,a+n);        llint maxi=9999999999;        llint count=0;        for(int i=0;i<n-1;i++)        {            mai[num]=a[i+1]-a[i];            if(mai[num]<maxi) maxi=mai[num];            num++;        }        for(int i=0;i<num;i++)        {            if(mai[i]==maxi)                count++;        }        cout<<maxi<<" "<<count<<endl;    }    return 0;}


0 0
原创粉丝点击