CF459B Pashmak and Flowers (水

Codeforces Round #261 (Div. 2)

B. Pashmak and Flowers
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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!

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.
Input

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

Output

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

Sample test(s)
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.

题意:男主要选一对花送女主,要一只是值最大的花,一只是值最小的花,问有多少种选择。

题解:先找到最大值、最小值,统计最大值元素个数nma、最小值元素个数nmi,若最大值不等于最小值则直接出nma*nmi,若等于则出C(nma,2)。

注意运算很容易超int,还是全用long long比较保险。

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) prllf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1biao.out","w",stdout)
#define mp make_pair ll n;
ll a[];
ll mi,ma,nma,nmi;
int main(){
ll i;
scanf("%I64d",&n);
mi=0xffffffff;
ma=;
REP(i,n){
scanf("%I64d",&a[i]);
mi=min(mi,a[i]);
ma=max(ma,a[i]);
}
nmi=;nma=;
REP(i,n){
if(a[i]==mi)nmi++;
if(a[i]==ma)nma++;
}
ll ans1=ma-mi;
ll ans2;
if(ans1!=)ans2=nma*nmi;
else ans2=(nmi)*(nmi-)/;
printf("%I64d %I64d\n",ans1,ans2);
return ;
}
上一篇:sgu 104 Little shop of flowers 解题报告及测试数据


下一篇:poj1157LITTLE SHOP OF FLOWERS