codeforces 458B
来源:互联网 发布:ios 存储数组 编辑:程序博客网 时间:2024/06/06 13:06
</pre><pre name="code" class="cpp">
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.
21 2
1 1
31 4 5
4 1
53 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.
#include<cstdio>#include<iostream>#include<cmath>#include<algorithm>using namespace std;typedef long long ll;int main(){ ll a[200000+5]; ll i,n,max,min,nmax,nmin; ll di; cin>>n; nmin=1,nmax=1; for(i=0;i<n;i++)cin>>a[i]; sort(a,a+n); max=a[0],min=a[0]; for(i=1;i<n;i++) { if(min>a[i]){nmin=1;min=a[i];} else if(min==a[i]){nmin++;} if(max<a[i]){nmax=1;max=a[i];} else if(max==a[i]&&a[i]!=min){nmax++;} } di=nmax*nmin; if(max==min) { di=n*(n-1)/2;} cout<<(ll)(max-min)<<" "<<(ll)di<<endl; return 0;}
这道题至少得了100个WA,气死了,全部改成LL!就好了
- codeforces 458B
- Codeforces 458B Distributed Join
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- Codeforces 1B - Spreadsheet
- codeforces 214B Hometask
- Codeforces Round #136 B
- 工作总结--民生的领导视图。
- python扩展实现方法--python与c混和编程(转)
- MATLAB学习心得~
- 定制导航栏和状态栏
- hadoop+hive-完全分布式环境搭建
- codeforces 458B
- 【爱上Java8】Java 8 不在需要ORM了
- LeetCode | Reverse Words in a String(字符串中的单词序反转)
- PyQt4在TextEdit控件中创建右键菜单
- Leetcode【15】:3Sum
- FASDVZXCVZXCV
- 二极管、三极管、场效应管的原理及特性
- 函数包装器,函数私有类处理
- C语言 select函数使用