New Bus Route

新人打cf多多关照

A. New Bus Route
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.


sort一下两个变量ans num记录更新就好无穷大要开足够大,,用long long 

#include<stdio.h>
#include<algorithm>
using namespace std;

#define ll long long
ll a[1000003];
int main()
{
    int n;

    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
            scanf("%lld",&a[i]);
        sort(a,a+n);
        ll ans=0x3f3f3f3f3f,num=0;
        for(int i=1; i<n; i++)
        {
            if(a[i]-a[i-1]<ans)
            {
                ans=a[i]-a[i-1];
                num=0;
            }
            if(a[i]-a[i-1]==ans)
            {
                num++;
            }
        }
        printf("%lld %lld\n",ans,num);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用和引用中提供的信息,原始的index.js文件中存在错误,导致路由无法正常工作。在修改后的index.js文件中,已经修复了这个错误,现在路由应该可以正常运行了。 然而,根据您提供的错误信息,问题出现在breadcrumb.vue文件的第25行,具体为"$route"属性未定义。这意味着在breadcrumb.vue组件中使用了$route属性,但是$route属性并未正确传递或定义。 为了解决这个问题,可以尝试在main.js文件中添加如下代码: ```javascript Vue.prototype.$bus = new Vue(); ``` 这段代码将创建一个事件总线(event bus),用于在无关联组件之间进行通信。将其定义为Vue的原型属性后,就可以在任何组件中使用`this.$bus`来进行事件的发布和订阅。 通过使用事件总线,您可以通过触发一个事件来传递$route属性给breadcrumb.vue组件。在需要获取$route属性的地方,可以使用`this.$bus.$emit`来发送事件,在breadcrumb.vue组件中使用`this.$bus.$on`来订阅事件并获取路由信息。 综上所述,您可以通过添加事件总线来解决"$route"属性未定义的问题,并确保breadcrumb.vue组件能够正确使用$route属性。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Vue路由报错:TypeError: Cannot read properties of undefined (reading ‘_self‘)undefined (reading ...](https://blog.csdn.net/weixin_43913958/article/details/131249314)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [Vue项目运行报错:“TypeError: Cannot read properties of undefined (reading ‘$on‘)](https://blog.csdn.net/m0_74152912/article/details/130653143)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值