time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.

Filya is given an array of non-negative integers a1, a2, ..., an.
First, he pick an integer x and then he adds x to
some elements of the array (no more than once), subtract x from some other elements (also, no more than once) and do no change other
elements. He wants all elements of the array to be equal.

Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in
order to make all elements equal.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 100 000) —
the number of integers in the Filya's array. The second line containsn integers a1, a2, ..., an (0 ≤ ai ≤ 109) —
elements of the array.

Output

If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line
of the output. Otherwise print "YES" (without quotes).

Examples
input
5
1 3 3 2 1
output
YES
input
5
1 2 3 4 5
output
NO
Note

In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second
and the third elements.

【题解】

这题看上去很吓人。

但其实想想。如果有4个或以上不同的数字。就根本不可能满足条件嘛。

3个的话是有可能的。就是中间那个数是中位数。

排序。然后去重,统计有多少个不同的数字。

【代码】

#include <cstdio>
#include <algorithm> using namespace std; const int MAXN = 109000; int a[MAXN],n; void input_data()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
} void get_ans()
{
sort(a + 1, a + 1 + n);
a[0] = 1;
for (int i = 2;i <= n;i++)
if (a[i] != a[i - 1])//这个去重方法是正确的
{
a[0]++;
a[a[0]] = a[i];
}
} void output_ans()
{
if (a[0] <= 2) //一个数也可以!
printf("YES\n");
else
if (a[0] == 3 && (a[1] + a[3]) == (a[2] * 2))
printf("YES\n");
else
printf("NO\n");
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
input_data();
get_ans();
output_ans();
return 0;
}

【31.95%】【CF 714B】Filya and Homework的更多相关文章

  1. 【codeforces】【比赛题解】#851 CF Round #432 (Div.2)

    cf真的难…… 点我浏览丧题. [A]Arpa和她对墨西哥人浪的研究 Arpa正在对墨西哥人浪进行研究. 有n个人站成一排,从1到n编号,他们从时刻0开始墨西哥人浪. 在时刻1,第一个人站起来.在时刻 ...

  2. LeetCode:下一个更大元素I【31】

    LeetCode:下一个更大元素I[31] 题目描述 给定两个没有重复元素的数组 nums1 和 nums2 ,其中nums1 是 nums2 的子集.找到 nums1 中每个元素在 nums2 中的 ...

  3. LeetCode:下一个排列【31】

    LeetCode:下一个排列[31] 题目描述 实现获取下一个排列的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列. 如果不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排 ...

  4. 剑指Offer:栈的压入、弹出序列【31】

    剑指Offer:栈的压入.弹出序列[31] 题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈 ...

  5. 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)

    A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...

  6. 【Android】【录音】Android录音--AudioRecord、MediaRecorder

    [Android][录音]Android录音--AudioRecord.MediaRecorder Android提供了两个API用于实现录音功能:android.media.AudioRecord. ...

  7. 【开源】C#.NET股票历史数据采集,【附18年历史数据和源代码】

    如果用知乎,可以关注专栏:.NET开源项目和PowerBI社区 重点重点:我没有买股票,没有买股票,股市是个坑,小心割韭菜哦. 本文的初衷是数据分析(分析结果就不说了,就是想看看筛选点数据),只不过搞 ...

  8. 【微信小程序项目实践总结】30分钟从陌生到熟悉 web app 、native app、hybrid app比较 30分钟ES6从陌生到熟悉 【原创】浅谈内存泄露 HTML5 五子棋 - JS/Canvas 游戏 meta 详解,html5 meta 标签日常设置 C#中回滚TransactionScope的使用方法和原理

    [微信小程序项目实践总结]30分钟从陌生到熟悉 前言 我们之前对小程序做了基本学习: 1. 微信小程序开发07-列表页面怎么做 2. 微信小程序开发06-一个业务页面的完成 3. 微信小程序开发05- ...

  9. day41 python【事物 】【数据库锁】

    MySQL[五] [事物 ][数据库锁]   1.数据库事物 1. 什么是事务  事务是应用程序中一系列严密的操作,所有操作必须成功完成,否则在每个操作中所作的所有更改都会被撤消.也就是事务具有原子性 ...

随机推荐

  1. 对象无法注册到Spring容器中,手动从spring容器中拿到我们需要的对象

    当前对象没有注册到spring容器中,此时无法new object()  的方式创建对象,否则所有@Autowired 注入的对象都为null; 处理方式: 手动创建一个类@Component注册到S ...

  2. Directx11教程(34) 纹理映射(4)

    原文:Directx11教程(34) 纹理映射(4)     本篇教程中,我们尝试在myTutorialD3D_27中改变采样状态描述符的各种设置,看纹理贴图的方式有什么变化. 原始的代码是:     ...

  3. python 同名变量引用

  4. mogodb 修改字段属性

    修改为decimal类型 db.shopgoods.find({'Pricing.Detail':{$type:2}}).forEach(function(x){x.Pricing.Detail=Nu ...

  5. Apache利用mod_limitipconn模块限制客户端多线程下载

    由于网站几次被人以搞并发弄跨了,所以百度了一堆方法.其中有一篇针对apache的能限制ip访问量.不允许同一ip大并发访问. 安装模块 yum install mod_limitipconn.x86_ ...

  6. QT 获取系统时间

    1.导入QTime #include <QTime> 2.定义QTime 对象接受当前时间 QTime t=QTime::currentTime(); t就是系统时间. 3.将t转化为st ...

  7. Python基础:13装饰器

    装饰器是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典的应用有插入日志.性能测试.事务处理等.装饰器是解决这类问题的绝佳设计,有了装饰器,我们就可以抽离出大量函数中与函数功能本身无关的雷同 ...

  8. 16-1 djanjo介绍

    一 web框架的本质 1用户的浏览器(socket客户端) 和 网站的服务器(socket服务端)之间 2 HTTP协议: 1.1 请求(request) 1.2. 响应(response) 3 we ...

  9. Mysql 锁表处理

    -- 查看正在被锁定的的表 show ; -- 查看进程号 show processlist; -- 杀掉进程 : -- 表级锁次数 show status like 'Table%'; +----- ...

  10. python selenium 基础框架

    base_page.py # coding=utf-8 import time from selenium.common.exceptions import NoSuchElementExceptio ...