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;
}

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/536384.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/536384.shtml
英文地址,請注明出處:http://en.pswp.cn/news/536384.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

愛說說技術原理:與TXT交互及MDataTable對Json的功能擴展(二)

2019獨角獸企業重金招聘Python工程師標準>>> 關于愛說說在技術選型的文章見&#xff1a;"愛說說"技術原理方案的定選思考過程 本篇將講述“愛說說”比較重大的技術問題點及解決手段&#xff1a; 愛說說&#xff1a;http://speak.cyqdata.com/ 雜說幾句&am…

ActiveXObject 安裝

將后綴名為ocx的文件拷貝至目錄 c:\Windows\SysWOW64\。執行如下命令&#xff0c;進行注冊&#xff1a;regsvr32 c:\Windows\SysWOW64\x.ocx轉載于:https://www.cnblogs.com/Currention/p/11024354.html

如何制作VSPackage的安裝程序

2019獨角獸企業重金招聘Python工程師標準>>> 第一步&#xff0c;生成一個REG文件&#xff1a; 收錢進入目錄: C:\Program Files\Microsoft Visual Studio 2008 SDK\VisualStudioIntegration\Tools\Bin 這是SDK的目錄&#xff0c;使用regpkg.exe 命令 命令格式為: …

MyBatis學習總結(1)——MyBatis快速入門

2019獨角獸企業重金招聘Python工程師標準>>> 一、Mybatis介紹 MyBatis是一個支持普通SQL查詢&#xff0c;存儲過程和高級映射的優秀持久層框架。MyBatis消除了幾乎所有的JDBC代碼和參數的手工設置以及對結果集的檢索封裝。MyBatis可以使用簡單的XML或注解用于配置和…

MyEclipse+Tomcat+MAVEN+SVN項目完整環境搭建

2019獨角獸企業重金招聘Python工程師標準>>> 這次換了臺電腦&#xff0c;所以需要重新配置一次項目開發環境&#xff0c;過程中的種種&#xff0c;記錄下來&#xff0c;便于以后再次安裝&#xff0c;同時給大家一個參考。 1.JDK的安裝 首先下載JDK&#xff0c;這個從…

Java基礎學習總結(10)——static關鍵字

2019獨角獸企業重金招聘Python工程師標準>>> 一、static關鍵字 原來一個類里面的成員變量&#xff0c;每new一個對象&#xff0c;這個對象就有一份自己的成員變量&#xff0c;因為這些成員變量都不是靜態成員變量。對于static成員變量來說&#xff0c;這個成員變量只…

ActiveMQ學習總結(3)——spring整合ActiveMQ

2019獨角獸企業重金招聘Python工程師標準>>> 1.參考文獻 Spring集成ActiveMQ配置Spring JMS異步發收消息 ActiveMQ2.環境 在前面的一篇 ActiveMQ入門實例中我們實現了消息的異步傳送&#xff0c;這篇博文將如何在spring環境下集成ActiveMQ。如果要在spring下集成Act…

Pots【廣搜,模擬】

Pots POJ - 3414 You are given two pots, having the volume of A and B liters respectively. The following operations can be performed: FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap;DROP(i) empty the pot i to the drain;POUR(i,j) pour fro…

非常可樂【廣搜,模擬】

非常可樂 HDU - 1495 大家一定覺的運動以后喝可樂是一件很愜意的事情&#xff0c;但是seeyou卻不這么認為。因為每次當seeyou買了可樂以后&#xff0c;阿牛就要求和seeyou一起分享這一瓶可樂&#xff0c;而且一定要喝的和seeyou一樣多。但seeyou的手中只有兩個杯子&#xff0…

問題 A: 深度學習

問題 A: 深度學習 時間限制: 1 Sec 內存限制: 128 MB 提交: 53 解決: 42 [提交] [狀態] [討論版] [命題人:admin] 題目描述 小 A 最近在研究深度學習&#xff0c;他自己搭建了一個很牛逼的神經網絡&#xff0c;現在他手頭一共有 n 組訓練數據&#xff0c;一開始他會給自己的…

堆樹

一、堆樹的定義 堆樹的定義如下&#xff1a; &#xff08;1&#xff09;堆樹是一顆完全二叉樹&#xff1b; &#xff08;2&#xff09;堆樹中某個節點的值總是不大于或不小于其孩子節點的值&#xff1b; &#xff08;3&#xff09;堆樹中每個節點的子樹都是堆樹。 當父節點的鍵…

問題 D: 最小生成樹II

問題 D: 最小生成樹II 時間限制: 1 Sec 內存限制: 128 MB 提交: 89 解決: 44 [提交] [狀態] [討論版] [命題人:admin] 題目描述 小A有一張n個點的帶權無向圖&#xff0c;這張無向圖非常特別&#xff0c;首先第i個點有一個點權ai&#xff0c;之后這張無向圖是一張完全圖&…

問題 G: 區間權值

問題 G: 區間權值 時間限制: 1 Sec 內存限制: 128 MB 提交: 112 解決: 49 [提交] [狀態] [討論版] [命題人:admin] 題目描述 小Bo有n個正整數a1..an&#xff0c;以及一個權值序列w1…wn&#xff0c;現在他定義 現在他想知道的值&#xff0c;需要你來幫幫他 你只需要輸出答案…

問題 I: 連通塊計數

問題 I: 連通塊計數 時間限制: 1 Sec 內存限制: 128 MB 提交: 108 解決: 45 [提交] [狀態] [討論版] [命題人:admin] 題目描述 小A有一棵長的很奇怪的樹&#xff0c;他由n條鏈和1個點作為根構成&#xff0c;第i條鏈有ai個點&#xff0c;每一條鏈的一端都與根結點相連。 現在…

telnet 功能啟用并測試端口是否正常

記錄日期&#xff1a;2019年6月21日 13點52分 操作系統&#xff1a;Windows 10 由于 Ping命令可以檢查網絡是否連通&#xff0c;但無法準確判斷某個端口是否連通&#xff0c;因此需要使用 Telnet協議。 1、打開控制面板中的程序和功能。 2、側邊欄&#xff0c;啟用或關閉Window…

步步為營 SharePoint 開發學習筆記系列 七、SharePoint Timer Job 開發

概要 項目需求要求我們每天晚上同步員工的一些信息到sharepoint 的user List &#xff0c;我們決定定制開發sharepoint timer Job,Sharepoint timer Job是sharePoint的定時作業Job,需要安裝、布曙到服務器上,而這里我只是介紹下Job開發的例子&#xff0c;以供大家學習用。 開發…

問題 J: 尋找復讀機【模擬】

問題 J: 尋找復讀機 時間限制: 1 Sec 內存限制: 128 MB 提交: 131 解決: 50 [提交] [狀態] [討論版] [命題人:admin] 題目描述 某個QQ群里一共有n個人&#xff0c;他們的編號是1..n&#xff0c;其中有一些人本質上是復讀機。 小A發現&#xff0c;如果一個人的本質是復讀機&…

windows下jenkins常見問題填坑

沒有什么高深的東西&#xff0c;1 2天的時間大多數人都能自己摸索出來&#xff0c;這里將自己遇到過的問題分享出來避免其他同學再一次挖坑. 目錄 1. 主從節點 2. Nuget自動包還原 3. powershell部署 4. 內網機器實現基于變化的構建 5. Github私有項目pull時限 所謂主從&#x…

Cow Contest【最短路-floyd】

Cow Contest POJ - 3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competitors. …

【學習Android NDK開發】Type Signatures(類型簽名)

類型簽名&#xff08;Type Signatures&#xff09; (<Parameter 1 Type Code>[<Parameter 1 Class>];...)<Return Type Code> The JNI uses the Java VM’s representation of type signatures. Following Table shows these type signatures. Type Signatur…