Alyona and Mex

题目链接:

http://acm.hust.edu.cn/vjudge/contest/121333#problem/B

Description

Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.

Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≤ bi ≤ ai for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array.

Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array.

The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.

Output

Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.

Sample Input

Input

5

1 3 3 3 6

Output

5

Input

2

2 1

Output

3

题意:

可以任意减小数组元素的大小,使得最小不出现的自然数最大;

题解:

排序后离散化即可;当出现不能离散化时即为最大的自然数.

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <queue>
  7. #include <map>
  8. #include <set>
  9. #include <vector>
  10. #define LL long long
  11. #define eps 1e-8
  12. #define maxn 110000
  13. #define inf 0x3f3f3f3f
  14. #define IN freopen("in.txt","r",stdin);
  15. using namespace std;
  16. int n;
  17. int a[maxn];
  18. int main(int argc, char const *argv[])
  19. {
  20. //IN;
  21. while(scanf("%d",&n) != EOF)
  22. {
  23. for(int i=1; i<=n; i++)
  24. scanf("%d", &a[i]);
  25. sort(a+1,a+1+n);
  26. int ans = 0;
  27. for(int i=1; i<=n; i++)
  28. if(a[i] > ans) ans++;
  29. printf("%d\n", ans+1);
  30. }
  31. return 0;
  32. }

CodeForces 682B Alyona and Mex (排序+离散化)的更多相关文章

  1. CodeForces 682B Alyona and Mex (题意水题)

    题意:给定一个序列,你可以对这里面的数用小于它的数来代替,最后让你求,改完后的最大的序列中缺少的最小的数. 析:这个题,读了两个多小时也没读懂,要是读懂了,肯定能做出来...没什么可说的,就是尽量凑1 ...

  2. Codeforces 740C. Alyona and mex 思路模拟

    C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

  3. Educational Codeforces Round 23 F. MEX Queries 离散化+线段树

    F. MEX Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. CodeForces 740C Alyona and mex

    构造. 比较骚的构造题.肯定可以构造出$min(R-L+1)$,只要$0$ $1$ $2$ $...$ $R-L$ $0$ $1$ $2$ $...$ $R-L$填数字即可,这样任意一段区间都包含了$ ...

  5. Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题

    B. Alyona and Mex 题目连接: http://www.codeforces.com/contest/682/problem/B Description Someone gave Aly ...

  6. Codeforces Round #381 (Div. 1) A. Alyona and mex 构造

    A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother want ...

  7. Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)

    C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative i ...

  8. Codeforces Round #358 (Div. 2)B. Alyona and Mex

    B. Alyona and Mex time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  9. CodeForces - 682B 题意水题

    CodeForces - 682B Input The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — ...

随机推荐

  1. oracle lsnrctl status|start|stop

    [oracle@redhat4 ~]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 06-OCT-2015 ...

  2. ogre, dx, opengl坐标矩阵

    opengl 右手坐标系 列向量 左乘 列主序存储矩阵osg   右手坐标系 行向量 右乘 行主序存储矩阵d3d       左手坐标系 行向量 右乘 行主序存储矩阵ogre    右手坐标系 列向量 ...

  3. max-height,min-height在IE下不支持的解决方法

    max-height,min-height在IE下不支持的解决方法 max-width:160px; max-height:160px; _width:expression(this.width &g ...

  4. 无法加载 DLL“rasapi32.dll”: 动态链接库(DLL)初始化例程失败。

    无法加载 DLL“rasapi32.dll”: 动态链接库(DLL)初始化例程失败. 在Asp.Net项目中使用WebClient或HttpWebRequest时出现以上错误 解决方案:把以下代码放在 ...

  5. c& c++ enum

    1.为什么要用enum       写程序时,我们常常需要为某个对象关联一组可选alternative属性.例如,学生的成绩分A,B,C,D等,天气分sunny, cloudy, rainy等等.   ...

  6. vc2005编译ffmpeg以及ffplay

    ffmpeg编译过程:1 http://ffmpeg.zeranoe.com/builds/下载官方提供的源码,win32库和dll.2 新建vc2005 console空工程,把ffmpeg.h,f ...

  7. 在Windows下编译ffmpeg完全手册

    本文的内容几乎全部来自于FFmpeg on Windows,但是由于国内的网络封锁,很难访问这个域名下的内容,因此我一方面按照我自己的理解和实践做了翻译,另一方面也是为了能提供一个方便的参考方法. 注 ...

  8. BOM浏览器对象模型和API速查

    什么是BOMBOM是Browser Object Model的缩写,简称浏览器对象模型BOM提供了独立于内容而与浏览器窗口进行交互的对象由于BOM主要用于管理窗口与窗口之间的通讯,因此其核心对象是wi ...

  9. session服务器Nginx+Tomcat+Memcached集群Session共享

    cookie是怎样工作的? 例如,我们创立了一个名字为login的Cookie来包含访问者的信息,创立Cookie时,服务器端的Header如下面所示,这里假设访问者的注册名是“Michael Jor ...

  10. Spring学习之声明式事物管理

    public List<Student> selectStudent() { Student s = new Student(); s.setName("zhengbin&quo ...