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 长度下, ...
随机推荐
- 查看.ssh文件在哪
输入命令 ll -d ~/.ssh 后你就都明白了.
- 字节、十六进制字符串相互转换(asc2hex、hex2asc)
//================================================================== /** 功能: 将16进制数组转换成asc字符数组(短转长) ...
- 并发容器之写时拷贝的 List 和 Set
对于一个对象来说,我们为了保证它的并发性,通常会选择使用声明式加锁方式交由我们的 Java 虚拟机来完成自动的加锁和释放锁的操作,例如我们的 synchronized.也会选择使用显式锁机制来主动的控 ...
- scrapy初试水 day03(递归调用)
import scrapyfrom scrapy.http import Requestfrom scrapy.spider import Rulefrom scrapy.linkextractors ...
- Cannot load browser "PhantomJS": it is not registered! Perhaps you are missing some plugin? 测试安装遇到的BUG
安装了半天phantomjs就是安装不好,后面想了个死办法,http://phantomjs.org/download.html这个网址下先去下载好 phantomjs-2.1.1-windows.z ...
- HTTP / 1.1 RFC from W3C
这是一篇关于http协议的学习资料: HTTP / 1.1 RFC: https://www.w3.org/Protocols/rfc2616/rfc2616.html HTTP协议的完整资料,请参考 ...
- CCS模块库文件的生成与使用
在一个大的项目中,为了便于管理,有时需要将一个模块封装为库文件,并可以在项目中使用. 图表 1 项目 步骤如下: 1.右键-->new-->CCS Project 图表 2 新建ccs p ...
- vue——props的两种常用方法
vue--props的两种常用方法 1.实现父-->子的通信 举例如下: 父组件 parent.vue <children :channel="object1"> ...
- 如何在Raspberry Pi 3B中安装RASPBIAN
RASPBIAN简介 RASPBIAN是树莓派官方支持的基于Debian的Linux系统.RASPBIAN预装了很多常用的组件,使用起来十分方便. 官方有RASPBIAN STRETCH WITH D ...
- html Embed用法 页面播放视频
一句话概括所有问题.查资料说在页面播放视频都是一些插件 刚发现一个Html自带的标签 很吊的样子 <div > <embed src="${compla ...