日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

New Bus Route

發布時間:2025/3/8 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 New Bus Route 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?New Bus Route

?CodeForces - 792A?

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.

Examples

Input

4 6 -3 0 4

Output

2 1

Input

3 -2 0 2

Output

2 2

Note

In the first example the distance between the first city and the fourth city is?|4?-?6|?=?2, and it is the only pair with this distance.

題目大意:求差值最小的數字的對數,但不能重復使用同一個數,標記一下即可

AC代碼

#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <map> #include <stack> #include <queue> #include <vector> #include <bitset> #include <set> #include <utility> using namespace std; typedef long long ll; #define inf 0x3f3f3f3f #define rep(i,l,r) for(int i=l;i<=r;i++) #define lep(i,l,r) for(int i=l;i>=r;i--) #define ms(arr) memset(arr,0,sizeof(arr)) //priority_queue<int,vector<int> ,greater<int> >q; const int maxn = (int)2e5 + 5; const ll mod = 1e9+7; int num[maxn]; int cha[maxn]; bool vis[maxn]; int p[maxn]; int main() {//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int n;cin>>n;memset(vis,false,sizeof(vis));ms(num);ms(p);ms(cha);rep(i,1,n) {cin>>num[i];}sort(num+1,num+1+n);int minl=mod*2;rep(i,1,n-1) {cha[i]=num[i+1]-num[i];minl=min(minl,cha[i]);}int ans=0;rep(i,1,n-1) {if(cha[i]==minl) {vis[i]=true;}}int i=1;int t=0;while(i<n) {if(vis[i]==true){t++;p[t]=1;i++;while(vis[i]==true){p[t]++;i++;}}elsei++;}/*rep(i,1,t)cout<<p[i]<<" ";cout<<endl;*/rep(i,1,t) {ans+=p[i];}cout<<minl<<" "<<ans<<endl;return 0; }

?

總結

以上是生活随笔為你收集整理的New Bus Route的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。