链接:http://codeforces.com/contest/459/problem/B
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:
- 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·105). In the next line there are n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ 109).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
2
1 2
1 1
3
1 4 5
4 1
5
3 1 2 3 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.
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
wa了无数次啊,这题到处是坑,不过题目真心不错
一开始看不懂题意,什么“maximum beauty difference”,这什么意思???看了N久,原来是花的最大魅力值差
好吧,一下有思路,没看数据量,wa了一次long long
然后又wa了一次脑抽筋
然后又wa了一次特判
然后又wa了一次全部相同的情况
…………
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm> using namespace std; int main() { long long maxx=0,minn=0,i,j;//wa one int str[300010]; int n; while(scanf("%d",&n)!=EOF) { minn=1,maxx=1; for(int i=0; i<n; i++) scanf("%d",&str[i]); sort(str,str+n); printf("%d ",str[n-1]-str[0]); //minn=str[0],maxx=str[0]; for(i=1; i<n; i++) { if(str[i] == str[0]) { minn++; } else break; } for(i=n-2; i>=0; i--) { if(str[n-1] == str[i]) maxx++; else break; } //if(str[n-1] == str[0])printf("1 ");//wa 2 //else if(n == 2 && str[0] == str[1])//wa 3 printf("1 "); else if(str[0] != str[n-1]) printf("%I64d ",maxx*minn); else if(str[0] == str[n-1]) printf("%I64d ",maxx*(maxx-1)/2);//wa 4 } return 0; }