cf459B Pashmak and Flowers
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 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.
这好像比A还水……输出极差,和两个数的差等于极差的方案数
然后直接输出最大值的个数乘最小值的个数好像会wa……我会告诉你n个1的情况答案是n*(n-1)/2吗
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,mx,mn;
int a[200010];
long long ans,m1,m2;
int main()
{
n=read();
for (int i=1;i<=n;i++)a[i]=read();
sort(a+1,a+n+1);
mn=a[1];mx=a[n];
for (int i=1;i<=n;i++)
{
if (a[i]==mx)m1++;
if (a[i]==mn)m2++;
}
ans=m1*m2;if (mx==mn)ans=(long long)(n-1)*n/2;
printf("%d %lld",mx-mn,ans);
}
cf459B Pashmak and Flowers的更多相关文章
- CF459B Pashmak and Flowers (水
Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...
- Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are nflowers in the garden ...
- codeforces 459 B.Pashmak and Flowers 解题报告
题目链接:http://codeforces.com/problemset/problem/459/B 题目意思:有 n 朵 flowers,每朵flower有相应的 beauty,求出最大的beau ...
- New Training Table
2014_8_15 CodeForces 261 DIV2 A. Pashmak and Garden 简单题 B. Pashmak and Flowers 简单题 C. P ...
- Codeforces Round #261 (Div. 2) B
链接:http://codeforces.com/contest/459/problem/B B. Pashmak and Flowers time limit per test 1 second m ...
- CF 459A && 459B && 459C && 459D && 459E
http://codeforces.com/contest/459 A题 Pashmak and Garden 化简化简水题,都告诉平行坐标轴了,数据还出了对角线,后面两个点坐标给的范围也不错 #in ...
- Codeforces Round #261 (Div. 2)[ABCDE]
Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...
- [codeforces] 暑期训练之打卡题(二)
每个标题都做了题目原网址的超链接 Day11<Given Length and Sum of Digits...> 题意: 给定一个数 m 和 一个长度 s,计算最大和最小在 s 长度下, ...
随机推荐
- QWidget可以设置QStyle,它可以绘制很多东西(具体内容没研究,待续)
QStyle * QWidget::style() const See also QWidget::setStyle(), QApplication::setStyle(), and QApplica ...
- rpm包制作
ubuntu下先下载sudo apt-get install rpm就行了. 然后测试下rpm和rpmbuild命令都是存在的.好了,OK. rpm安装包的制作有严格的自定义的路径,这个路径是在/us ...
- c3p0链接池
频繁的链接数据库是非常消耗性能的,所以就采用了将一定量的链接保存在一个池中,这个池我们叫做链接池. 详细请看:http://baike.baidu.com/link?url=dlTW-fTS3N_-j ...
- AIX5.3CPU占用高的问题核查
AIX5.3 CPU占用高问题核查步骤 1.topas查看占用cpu占用最高的进程的PID 2.执行: ps -mp PID -o THREAD 以查找相应进程下所有正在占用 CPU 的线程的TID ...
- hdu 4355 Party All the Time(三分搜索)
Problem Description In the Dark forest, there is a Fairy kingdom where all the spirits will go toget ...
- vi/vim经常使用命令
工作模式 插入命令 a 在光标后附加文本 A 在本行行尾附加文本 i 在光标前插入 I 在本行行首插入文本 o 在光标以下插入新的一行 O 在光标上面插入新的一行 定位命令 h 左移一个字符/ 向左的 ...
- ubuntu如何开启SSH服务
ubuntu如何开启SSH服务 分类: Linux 运维与操作基础2013-02-24 13:33 2868人阅读 评论(0) 收藏 举报 sshd ubuntu ubuntu默认并没有安装ssh服务 ...
- 伪元素::before和::after
有时候我们的页面里面有不少其他网站的名字,而且还要求网站名后面还要有网站的链接,类似这样:百度(http://www.baidu.com).这个时候如果网站多的话写起来就很麻烦了 <a href ...
- 浅谈JavaScript DOM编程艺术读后感和一点总结
最近工作不是很忙就想想想JavaScript的内部组成和一些要点,就是从这本书开始的.对新手来说还好,简单易懂. 简单终结下我重书中学到的一些要点. 下面都是个人学习的要点提取: 1.给自己预留退路, ...
- 自动化单元测试工具 EvoSuite 的简单使用
一.EvoSuite简介 EvoSuite是由Sheffield等大学联合开发的一种开源工具,用于自动生成测试用例集,生成的测试用例均符合Junit的标准,可直接在Junit中运行. 通过使用此自动测 ...