B - Alyona and Mex

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 every1 ≤ 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

51 3 3 3 6

Output

5

Input

22 1

Output

3

题意:

给出n个元素,元素可交换或减小,求最终缺少的最小正整数的最大值(mex)。

仔细观察我们不难看出当n个元素为从1~n递增时mex取最大值,如n=5时,1,2,3,4,5,mex取最大值6。所以我们就将数列尽量接近梁旭递增数列。

如1 3 3 3 6可改为1 2 3 3 4则取最大值mex为5。

附AC代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6
 7 const int MAX=101000;
 8
 9 int a[MAX];
10
11 int main(){
12     int n;
13     while(cin>>n){
14         for(int i=0;i<n;i++){
15             cin>>a[i];
16         }
17         int ans=1;
18         sort(a,a+n);//排序
19         for(int i=0;i<n;i++){
20             if(a[i]>=ans)//注意等于
21             ans++;
22         }
23         cout<<ans<<endl;
24     }
25     return 0;
26 } 
时间: 2024-08-03 02:53:19

B - Alyona and Mex的相关文章

Codeforces Round #381 (Div. 2) Alyona and mex

Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of th

#381 Div2 Problem C Alyona and mex (思维 &amp;&amp; 构造)

题意 : 题目的要求是构造出一个长度为 n 的数列, 构造条件是在接下来给出的 m 个子区间中, 要求每一个子区间的mex值最大, 然后在这 m 个子区间产生的mex值中取最小的输出, 并且输出构造出来的序列, 一个mex值的定义是这个区间没有出现过的最小的正整数, 例如(0, 2, 3)的mex = 1    (0, 1, 2)的mex=3 分析 : 发现在这m个mex值中, 最小的肯定是区间长度最小的, 而且这个mex值肯定是等于这个区间的长度, 记这个mex为Min(mex)所以输出的就是

CodeForces 740C Alyona and mex

构造. 比较骚的构造题.肯定可以构造出$min(R-L+1)$,只要$0$ $1$ $2$ $...$ $R-L$ $0$ $1$ $2$ $...$ $R-L$填数字即可,这样任意一段区间都包含了$0$ $1$ $2$ $...$ $R-L$. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath&

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

题意:给定一个序列,你可以对这里面的数用小于它的数来代替,最后让你求,改完后的最大的序列中缺少的最小的数. 析:这个题,读了两个多小时也没读懂,要是读懂了,肯定能做出来...没什么可说的,就是尽量凑1 2 3 4 5...如果没有了,就输出. 代码如下: #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int a[maxn]; int main(){ int n; while(cin >>

Codeforces Round #358 (Div. 2)

4/5 又是三题滚粗了,注定是打铁的命~~ 题A Alyona and Numbers 题意:给你n和m,找[1, n]和[1,m]范围内的两个数相加,有多少个的和是5的倍数? 题解:枚举x在[1,n]的范围,然后得到范围[x + 1, x + m]的数,求有多少个是5的倍数即可. 1 /*zhen hao*/ 2 #include <bits/stdc++.h> 3 using namespace std; 4 5 #define lson l, m, rt*2 6 #define rson

CODEFORCES ROUND #740 ANALYSES BY TEAM:RED &amp; BLACK

A.Alyona and copybooks Problems: 给你一个数n和代价分别为a, b, c.数量不限的1, 2, 3,求将n凑成4的倍数的最小代价 Analysis: cj:取个模随便凑一凑就好 Tags: Implementation 1 #define PRON "pa" 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <alg

思维-CF-739A

http://codeforces.com/problemset/problem/739/A Alyona and mex 对于一个非负整数数列a,定义mex(l, r)为不存在于a[l]~a[r]区间内的最小非负整数. 给定数列长度n,区间个数m.要求构造一个长度为n的数列使得这m个区间的最小mex最大. 输出m个区间的最小mex,以及构造的数列(多组解时只需要输出一组解即可) 解题报告 思路 (一开始没看懂题目....) 对于一个长度为Len的区间,这个区间的mex最大值显然为Len. 那么

[BZOJ3585][BZOJ3339]mex

试题描述 有一个长度为n的数组{a1,a2,...,an}.m次询问,每次询问一个区间内最小没有出现过的自然数. 输入 第一行n,m.第二行为n个数.从第三行开始,每行一个询问l,r. 输出 一行一个数,表示每个询问的答案. 输入示例 5 5 2 1 0 2 1 3 3 2 3 2 4 1 2 3 5 输出示例 1 2 3 0 3 数据规模及约定 对于100%的数据:1<=n,m<=2000000<=ai<=1091<=l<=r<=n 题解 首先离线,将询问按右端

Codeforces Round #401 (Div. 2) C. Alyona and Spreadsheet

题目链接:C. Alyona and Spreadsheet 题意: 给你一个n*m的矩阵,现在有k个询问,每次给你一个l,r,问你在[l,r]这行中能否有一列数十非递减的顺序 题解: 用vector来保存矩阵. 对于每一行n*m dp一下最远能达到的范围,然后询问的时候就判断l,r是否在这个范围内. 1 #include<bits/stdc++.h> 2 #define pb push_back 3 #define rs m+1,r,rt<<1|1 4 #define mst(a