CodeForces 459B

B. Pashmak and Flowers

Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!

Pashmak决定给Parmida花园的一对花。花园里有n个花,其中第i个有美丽值bi。Parmida是一个非常奇怪的女孩,所以她不想必须要有两个最美丽的花朵。她想要双花,它们美丽值差是尽可能的最大!

Your task is to write a program which calculates two things:

  1. The maximum beauty difference of flowers that Pashmak can give to Parmida.
  2. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.

你的任务是编写一个程序,计算两件事:

1、Pashmak可以给 Parmida的美丽值差别最大的鲜花。

2、Pashmak可以摘花的方式。两种方法被认为是不同的,当且仅当至少有一个花,选择第一种方式,而不是选择第二种方式。 

Input

The first line of the input contains n (2 ≤ n ≤ 2·10^5). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 10^9).

输入的第一行包含 n (2 ≤ n ≤ 2·10^5)。下一行中有n个空格分隔的整数b1, b2,…,bn (1 ≤ bi ≤ 10^9)。

Output

The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.

唯一的输出应该包含两个整数。分别输出最大的美丽差值和可能发生的方式数量。

Examples

Input

2
1 2

Output

1 1

Input

3
1 4 5

Output

4 1

Input

5
3 1 2 3 1

Output

2 4

 

Note

In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:

  1. choosing the first and the second flowers;
  2. choosing the first and the fifth flowers;
  3. choosing the fourth and the second flowers;
  4. choosing the fourth and the fifth flowers.

在第三个样本最大值美丽的差异是2,有四种方法去这么做:

  1. 选择第一个和第二个花;
  2. 选择第一个和第五个花;
  3. 选择第四和第二个花;
  4. 选择第四和第五的花。

思路 :

拿到题就可以知道是求一个数组里最大的差值并找出最大差值共有几个情况,所以一开始是先将花朵的美丽值全存进数组,一开始用int去创建数组,后面发现不太行,因为美丽值太大了,int存不上,容易溢出段错误的情况,然后换成longlong就好了;存进数组后就可以用sort函数去排序了,我还以为longlongsort排不了,结果还是能很完美的排序成功了,太牛了。排序完就知道了最大值和最小值了,就先算出最大的差值,然后在遍历去计算在数组内还有没有存在最大差值的情况,有就记录下来,然后最后输出就好。

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
    
    long long f [200010];//用来存花的美丽值
    long long n;
    int i;
    scanf("%lld",&n);
    for(i=0;i<n;i++){ 
        scanf("%lld",&f[i]);
    }
    sort(f,f+n);//先排序
    long long mn,mx,d;
    long long a=0,b=0;
    mn=f[0];//先存最大值最小值
    mx=f[n-1];
    d=mx-mn;//求出最大最小差值
    
    //分别算出花的最大最小美丽值相同值有几个
    for(i=0;i<n;i++){
        if(f[i]==mn) a++;
    }
    for(int i=n-1;i>=0;i--){
        if(f[i]==mx) b++;
    }
    
     if(mx==mn) printf("%lld %lld",d,n*(n-1)/2);//全部花朵的美丽值一样的情况
    else printf("%lld %lld",d,a*b);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值