首页 > 其他 > 详细

Codeforces Round #261 (Div. 2) 459B. Pashmak and Flowers(数学题,组合)

时间:2014-08-16 22:34:21      阅读:485      评论:0      收藏:0      [点我收藏+]

题目链接:http://codeforces.com/problemset/problem/459/B


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 b1b2, ..., 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.

代码如下:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps = 1e-9;
#define INF 1e18
//typedef long long LL;
typedef __int64 LL;
#define MAXN 200017
int main()
{
    LL n;
    LL a[MAXN], b[MAXN];
    while(~scanf("%I64d",&n))
    {
        LL i;
        LL maxx = 0, minn = 1000000000;
        for(i = 0; i < n; i++)
        {
            scanf("%I64d",&a[i]);
            if(a[i] > maxx)
                maxx = a[i];
            if(a[i] < minn)
                minn = a[i];
        }
        LL cont1 = 0, cont2 = 0;
        if(maxx == minn)
        {
            printf("0 %I64d\n",n*(n-1)/2);
            continue;
        }
        for(i = 0; i < n; i++)
        {
            if(a[i] == maxx)
                cont1++;
            else if(a[i] == minn)
                cont2++;
        }
        LL d = maxx-minn;
        printf("%I64d %I64d\n",d,cont1*cont2);
    }
    return 0;
}


Codeforces Round #261 (Div. 2) 459B. Pashmak and Flowers(数学题,组合),布布扣,bubuko.com

Codeforces Round #261 (Div. 2) 459B. Pashmak and Flowers(数学题,组合)

原文:http://blog.csdn.net/u012860063/article/details/38617151

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!