题解:找出序列中的最小值和最大值之差即为第一个输出,遍历一遍序列,分别找出最小值和最大值出现的次数,相乘即为总共的方法数量。不过,要注意几点:
1. 如果二者出现次数相等,即序列中的值全相同,则方法数量为C(n, 2),即n*(n-1) / 2;
2. n应定义为long long 或者(long long)n*(n-1) / 2LL,因为没开long long所以重判的时候WA掉了,可惜了
//Pashmak and Flowers.cpp
#include <bits/stdc++.h>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
freopen("D:\\Documents\\Programs\\Acm\\input.txt", "r", stdin);
#endif
int n; cin >> n;
int beauty[200005];
for(int i = 0; i < n; i++) {
scanf("%d", beauty + i);
}
sort(beauty, beauty + n);
cout << beauty[n-1] - beauty[0] << ' ';
LL cnt_low = 0, cnt_high = 0;
for(int i = 0; i < n; i++) {
if (beauty[i] == beauty[0]) cnt_low++;
if (beauty[i] == beauty[n-1]) cnt_high++;
}
if (cnt_low == cnt_high && cnt_low == n) {
cout << (LL)n*(n-1) / 2 << endl;
}
else cout << cnt_low * cnt_high << endl;
return 0;
}