链接:http://codeforces.com/contest/459/problem/B

B. Pashmak and Flowers
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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:

  1. The maximum beauty difference of flowers that Pashmak can give to Parmida.
  2. 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.

Sample test(s)
input
2
1 2
output
1 1
input
3
1 4 5
output
4 1
input
5
3 1 2 3 1
output
2 4
Note

In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:

  1. choosing the first and the second flowers;
  2. choosing the first and the fifth flowers;
  3. choosing the fourth and the second flowers;
  4. choosing the fourth and the fifth flowers.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

wa了无数次啊,这题到处是坑,不过题目真心不错

一开始看不懂题意,什么“maximum beauty difference”,这什么意思???看了N久,原来是花的最大魅力值差

好吧,一下有思路,没看数据量,wa了一次long long

然后又wa了一次脑抽筋

然后又wa了一次特判

然后又wa了一次全部相同的情况

…………

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std; int main()
{
long long maxx=,minn=,i,j;//wa one
int str[];
int n;
while(scanf("%d",&n)!=EOF)
{
minn=,maxx=;
for(int i=; i<n; i++)
scanf("%d",&str[i]);
sort(str,str+n);
printf("%d ",str[n-]-str[]);
//minn=str[0],maxx=str[0];
for(i=; i<n; i++)
{
if(str[i] == str[])
{
minn++;
}
else break;
}
for(i=n-; i>=; i--)
{
if(str[n-] == str[i])
maxx++;
else break;
}
//if(str[n-1] == str[0])printf("1\n");//wa 2
//else
if(n == && str[] == str[])//wa 3
printf("1\n");
else if(str[] != str[n-])
printf("%I64d\n",maxx*minn);
else if(str[] == str[n-])
printf("%I64d\n",maxx*(maxx-)/);//wa 4
}
return ;
}

Codeforces Round #261 (Div. 2) B的更多相关文章

  1. Codeforces Round #261 (Div. 2)[ABCDE]

    Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...

  2. Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP

    http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35  36组数据 ...

  3. Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida&#39;s problem(求逆序数对)

    题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...

  4. Codeforces Round #261 (Div. 2) - E (459E)

    题目连接:http://codeforces.com/contest/459/problem/E 题目大意:给定一张有向图,无自环无重边,每条边有一个边权,求最长严格上升路径长度.(1≤n,m≤3 * ...

  5. Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题

    题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...

  6. Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)

    题目链接:http://codeforces.com/problemset/problem/459/A A. Pashmak and Garden time limit per test 1 seco ...

  7. Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP

    题意:n个点,m条边,每条边有一个权值,找一条边数最多的边权严格递增的路径,输出路径长度. 解法:先将边权从小到大排序,然后从大到小遍历,dp[u]表示从u出发能够构成的严格递增路径的最大长度. dp ...

  8. Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --树状数组

    题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求有多少对这样的(i,j). 解法:分别从左到右,由右到 ...

  9. Codeforces Round #261 (Div. 2)

    第一场难得DIV2简单+AK人数多: E:给出一张图,求最多的边数,满足:在这个边的集合中后面的边的权值大于前面的边; 思路:我们将图按权值排列,以为只可能边权值小的跟新权值大的所以对于一条边我们只跟 ...

随机推荐

  1. tcp socket

    1.TCP连接手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过无线网络建立TCP连接.TCP协议可以对上层网络提供接口,使上层网络数据的传输建立在"无差别&quo ...

  2. while DEMO

    while DEMO #!/bin/bash #author:xiluhua #since: let v_count= " ] do ] then sleep echo $v_count l ...

  3. struts2结果类型

    struts2结果类型: 结果类型 描述 前request域属性是否丢失 1 dispatcher 用于与jsp整合的结果类型.默认结果类型. 2 chain Action链式处理结果类型.前一个Ac ...

  4. 微信开放平台API开发资料

    微信大概两年前开启了微信公众平台的API供开发者使用,从账号登陆.消息发送.用户账号管理.公众号菜单.客服接口.微信商店接口.用户卡券接口 以及微信支付接口.可以说是全方面覆盖了电商所需要的要素,与阿 ...

  5. Effective C++第三遍

    试图调用private的copy或赋值函数是编译期错误,而调用没有具体定义的函数则是连接期错误. 以对象管理资源:智能指针RAII(资源获取立即初始化)后都是对象,但有时候,比如(API的)函数参数要 ...

  6. 查看mysql的状态

    实时查看mysql状态连接数 查询数 etc mysqladmin  -uroot  -p '' -h status -i 1

  7. Python repr() 或str() 函数(转)

    Python 有办法将任意值转为字符串:将它传入repr() 或str() 函数.函数str() 用于将值转化为适于人阅读的形式,而repr() 转化为供解释器读取的形式(如果没有等价的语法,则会发生 ...

  8. 关于left join、right join和inner join

    总结, 1.select * from A left join B on A.XX=B.XX 左侧显示A的列名,右侧显示B的列名 左侧,显示A表的所有列 右侧, A.XX=B.XX的时候,显示B表的列 ...

  9. c# Beginlnvoke 委托

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. Obj格式解析以及在Unity3D下导入测试

    目前基本实现了导入,注意只能打开含有单个模型的obj文件 四边面模型: 全三角面模型(测试单一材质,自动分了下UV): 这里介绍下obj格式: obj格式是waveFront推出的一种3D模型格式,可 ...