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相关推荐

  1. UVALive 3353 Optimal Bus Route Design

    UVALive 3353 Optimal Bus Route Design 二分图最大完美匹配 题目 题目给出一个带权有向图,找若干个圈,使得每个结点切好属于一个圈,并且所有圈的总长度最小,如果没有满 ...

  2. 【UVALive】 3353 Optimal Bus Route Design 费用流

    传送门:[UVALive]3353 Optimal Bus Route Design 题目大意:给出一个n(n <= 100)个点的有向带权图,找若干个圈,使得每个结点恰好属于一个圈.要求总长度 ...

  3. UVA 1349 Optimal Bus Route Design (二分图最小权完美匹配)

    恰好属于一个圈,那等价与每个点有唯一的前驱和后继,这让人想到了二分图, 把一个点拆开,点的前驱作为S集和点的后继作为T集,然后连边,跑二分图最小权完美匹配. 写的费用流..最大权完美匹配KM算法没看懂 ...

  4. UVALive 3353 - Optimal Bus Route Design(二分图最小权匹配)

    题目链接 https://cn.vjudge.net/problem/UVALive-3353 [题意] 给你n个点(n<=100)的有向带权图,你要找到n个有向环,使得每个点恰好属于一个环,要 ...

  5. Uvalive3353 Optimal Bus Route Design 带权二分图匹配

    题目描述:给出一个有向带权图,现在要求在图中找出若干个环,使得每个点恰好在一个环里,且所有环的距离之和最小,如果不能使每个点恰好在一个环里,输出"N". 思路: 将每个点u拆成u和 ...

  6. UVALive - 3353 Optimal Bus Route Design(二分图最佳匹配)

    题目大意:给出一个n个点的有向带权图,找若干个圈,使得每个节点恰好属于一个圈,要求总长度尽量小 解题思路:首先要在一个圈内,且只能在一个圈内,那么每个点的入度和出度要都为1,所以二分图就有了 接着连边 ...

  7. [Leetcode] Bus Routes 公交线路

    Bus Routes 详细解题思路请访问:https://yanjia.me/zh/2018/11/... We have a list of bus routes. Each routes[i] i ...

  8. 【CodeForces - 864C】Bus (模拟,有坑)

    题干: A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting ...

  9. code forces 436 C. Bus

    C. Bus time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

最新文章

  1. 宏的使用 extern
  2. C# HttpHelper帮助类,真正的Httprequest请求时无视编码,无视证书,无视Cookie,网页抓取...
  3. 前后端分离 跨域问题解决
  4. Core Data 编程指南
  5. 在SAP ABAP 里consume webservice的全过程
  6. php和mysql一键安装包_iis+php+mysql一键安装教程和安装包
  7. (原+转)使用opencv的DFT计算卷积
  8. mysql的Innodb为什么使用B+树
  9. Boston波士顿房价数据下载
  10. eclipse 连接mysql 数据库 实现数据库基本操作
  11. 360p2刷无线打印服务器,【联网版】360路由器P2刷tomato固件小白教程
  12. python爬股指期货数据_新浪期货数据接口API(实时数据/历史数据)
  13. TSRC靶场赛-writeup
  14. 9大电商平台开具发票页调研
  15. matlab中rand(‘seed‘,任意符号)是干什么的?
  16. 【Lua笔记】、Lua元表
  17. 太牛了!高考失利只能进清华,35岁成阿里最年轻技术副总裁,他来自另一个平行世界!...
  18. 华为无线路由器信道怎么测试软件,教你为无线路由器选择合适的信道让上网更快...
  19. 免费帝国CMS插件实现seo优化提升网站排名
  20. 用巴特沃斯滤波器进行潮汐滤波分析

热门文章

  1. vs2010中引入boost库
  2. 加载不同linux内核,Linux内核加载过程
  3. 在微型计算机系统中,打印机一般是通过( ,2013湖南省计算机等级考试试题 二级C试题最新考试试题库...
  4. python优雅编程_Python优雅地可视化数据
  5. 微型计算机各部件之间通过总线传递各种信息,2015年9月计算机一级考试基础及MSOffice应用选择真题...
  6. html5 电流效果,在HTML5 Canvas 2D上绘制云雾中的电流动画特效
  7. 用python做简单的地理聚类分析案例_用Python做一个简单的翻译工具
  8. js判断ipad还是安卓_JS判断客户端是否是iOS或者Android
  9. iphone储存空间系统怎么清理_教你快速清理 iPhone 系统缓存垃圾,拒绝卡顿!
  10. html hover效果下拉个框,关于下拉菜单(CSS)中,“:hover”样式的设置问题?