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比较保险。

 1 //#pragma comment(linker, "/STACK:102400000,102400000")
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<iostream>
 5 #include<cstring>
 6 #include<algorithm>
 7 #include<cmath>
 8 #include<map>
 9 #include<set>
10 #include<stack>
11 #include<queue>
12 using namespace std;
13 #define ll long long
14 #define usll unsigned ll
15 #define mz(array) memset(array, 0, sizeof(array))
16 #define minf(array) memset(array, 0x3f, sizeof(array))
17 #define REP(i,n) for(i=0;i<(n);i++)
18 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
19 #define RD(x) scanf("%d",&x)
20 #define RD2(x,y) scanf("%d%d",&x,&y)
21 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
22 #define WN(x) prllf("%d\n",x);
23 #define RE  freopen("D.in","r",stdin)
24 #define WE  freopen("1biao.out","w",stdout)
25 #define mp make_pair
26 
27 ll n;
28 ll a[222222];
29 ll mi,ma,nma,nmi;
30 int main(){
31     ll i;
32     scanf("%I64d",&n);
33     mi=0xffffffff;
34     ma=0;
35     REP(i,n){
36         scanf("%I64d",&a[i]);
37         mi=min(mi,a[i]);
38         ma=max(ma,a[i]);
39     }
40     nmi=0;nma=0;
41     REP(i,n){
42         if(a[i]==mi)nmi++;
43         if(a[i]==ma)nma++;
44     }
45     ll ans1=ma-mi;
46     ll ans2;
47     if(ans1!=0)ans2=nma*nmi;
48     else ans2=(nmi)*(nmi-1)/2;
49     printf("%I64d %I64d\n",ans1,ans2);
50     return 0;
51 }
View Code

 

posted @ 2014-08-16 09:15  带鱼Yuiffy  阅读(340)  评论(0编辑  收藏  举报