1 second

256 megabytes

standard input

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 *b*_{i}. 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:

- The maximum beauty difference of flowers that Pashmak can give to Parmida.
- 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.

The first line of the input contains *n* (2 ≤ *n* ≤ 2·10^{5}). In the next line there are *n* space-separated integers *b*_{1}, *b*_{2}, …, *b*_{n}(1 ≤ *b*_{i} ≤ 10^{9}).

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

1 2 |
2 1 2 |

1 |
1 1 |

1 2 |
3 1 4 5 |

1 |
4 1 |

1 2 |
5 3 1 2 3 1 |

1 |
2 4 |

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

- choosing the first and the second flowers;
- choosing the first and the fifth flowers;
- choosing the fourth and the second flowers;
- choosing the fourth and the fifth flowers.

这个题其实就是记录数组的最大值和最小值的个数, 注意输出结果的数值范围要给够, 还有就是如果所有的数字都相等的话应该输出n-1的累和, 即1+2+3+4+…+n-1

By 何孟海

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
/************************************************************************* > File Name: 20140815261B.cpp > Author: razrLeLe > Personal homepage: https://razrLeLe.com > Created Time: Sat 16 Aug 2014 12:51:23 AM CST ************************************************************************/ #include<iostream> using namespace std; #include<cstdio> int main(){ long long n,b; long long final = 0; scanf("%I64d", &n); long long minb=1000000010, maxb=0; long long minn=0,maxn=0; for(int i = 0 ; i < n; i++) { scanf("%I64d",&b); if(maxb<b){ maxb=b; maxn=1; } else if(maxb==b) maxn++; if(minb>b){ minb=b; minn=1; } else if(minb==b) minn++; } if(maxb == minb) { for(int i = 0; i < n; i++) final+= i; } else { final = maxn * minn; } printf("%I64d %I64dn",maxb-minb,final); return 0; } |