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 长度下, ...
随机推荐
- Maven引入jar的总结
Overview:显示maven项目的一些基本信息 Dependencies:添加jar包的页面 Plugins:添加maven插件的页面.比如tomcat-maven-plugin等 Reporti ...
- 加密代理和Retrofit解密Converter
最近在研究安卓的Retrofit框架,服务器的数据全部用加密算法加密了,发现无法使用"com.squareup.retrofit2:converter-gson:2.1.0"Jar ...
- SSM框架开发web项目系列(一) 环境搭建篇
前言 开发环境:Eclipse Mars + Maven + JDK 1.7 + Tomcat 7 + MySQL 主要框架:Spring + Spring MVC + Mybatis 目的:快速上手 ...
- 深度解析continue,break和return
continue,break和return是Java中的关键字,在方法体内的流程控制中使用频率较高. 在现实中,经常会有同学在使用中产生混淆,从而使得流程控制语句发生混乱.在这里,我结合个人的使用经历 ...
- python中使用selenium调用Firefox缺少geckodriver解决方法
from selenium import webdriver driver=webdriver.Firefox() 会报错 解决方法: 因为缺少geckodriver.exe,先到https://gi ...
- openstack pike 使用 linuxbridge + vxlan
#openstack pike 使用 linuxbridge + vxlan #openstack pike 集群高可用 安装部署 汇总 http://www.cnblogs.com/elvi/p/ ...
- 实用的jQuery技巧
1.回到顶部按钮 利用jQuery里的animate和scrollTop方法,你便不需要使用插件创建简单的滚动到顶部动画. // Back to top $('.top').click(functi ...
- 利用阿里云Centos7建站过程
以下可能不尽详述,如有问题欢迎指出 准备过程:1. 阿里云主机一台2.域名一个 3.github个人帐号开始: 1.以root帐号登录云主机 2.安装apache [root@192 ~]# yum ...
- 逆向实用干货分享,Hook技术第二讲,之虚表HOOK
逆向实用干货分享,Hook技术第二讲,之虚表HOOK 正好昨天讲到认识C++中虚表指针,以及虚表位置在反汇编中的表达方式,这里就说一下我们的新技术,虚表HOOK 昨天的博客链接: http://www ...
- linux安装redis(转)
一.Redis介绍 Redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcache类似,但很大程度补偿了Memcache的不足,它支持存储的value类型相对更多 ...