Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are nflowers 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.
Input
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).
Output
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
Example
Input Output
Input Output
Input Output
Note
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.
my code is folowing.
#include <iostream>
using namespace std;
int main()
{
long long n;
while( cin >> n )
{
int i;
long long *b=new long long[n];
for(i=0;i<n;i++)
cin>>b[i];
long long maxn=b[0],minn=b[0],m=0,k=0;
for(i=0;i<n;i++)
{
if(b[i]>maxn)
maxn=b[i];
}
for(i=0;i<n;i++)
{
if(b[i]<minn)
minn=b[i];
}
for(i=0;i<n;i++)
{
if(b[i]==maxn)
m=m+1;
if(b[i]==minn)
k=k+1;
}
cout<<(maxn-minn)<<" "<<(maxn==minn)?(n*(n-1)/2):(m*k);
}
return 0;
}
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 ...
- cf459B Pashmak and Flowers
B. Pashmak and Flowers time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...
- 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 长度下, ...
随机推荐
- 常用的redis命令
常用的redis命令 http://www.runoob.com/redis/redis-tutorial.html 菜鸟教程 Cmd连接有密码的redis:$ redis-cli -h ho ...
- c++头文件重复引用问题
引子----之前写C++ 时遇到的坑 之前由于Java实在太好用了,C++的工程代码几乎没怎么碰,真的写起来的时候总会有些小bug,这里就对其中的一个进行个总结 a.h #include " ...
- 开始你的第一个npm脚本工具
在实际开发中,一般刚开始一个项目或者刚接手一个项目,我们会运行 npm install 下载安装所有依赖, 在实际开发中,可能也会使用各种命令行-- 来提高我们开发的效率. 与它相处了这么久,你真的了 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- 算法训练 区间K大数
算法训练 区间k大数查询 时间限制:1.0s 内存限制:256.0MB 问题描述 给定一个序列,每次询问序列中第l个数到第r个数中第K大的数是哪个. 输入格式 第一行包含一个数n,表示序列长度. ...
- KD-tree详解
转载自:http://blog.csdn.NET/zhjchengfeng5/article/details/7855241 首先来一个问题: 给定平面上一个点集 E ,还有一个定点 V ,怎么在一群 ...
- oracle中 常用的 join on 相关和 集合运算的总结
sql常用联合查询的 join on . left join(左连接) . right join (右连接).inner join (等值连接)以及常用的集合运算有:union.unionall.mi ...
- Spring之bean二生命周期
上一博客主要学习了下bean的配置.注入.自定义属性编辑器,今天来熟悉bean的生命周期.在开发中生命周期是一个很常见的名词,基本每种编程语言都能找到与它关联的.关于bean的生命周期我在网上也找了好 ...
- Linux权限相关操作命令
以下是关于创建用户,设置用户密码,以及查看文件权限,给用户设置权限的一系列操作过程. #查看当前用户的信息[root@VM_64_7_centos tmp]# iduid=0(root) gid=0( ...
- git上传本地文件到gitlab
The repository for this project is empty If you already have files you can push them using command l ...