CF | Alyona and Mex
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.
Example
5
1 3 3 3 6
5
2
2 1
3
Note
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements.
题意:给定n个元素的数组,让你输出最大的Mex (是不出现在这个数组中的最小正整数),然而,数组是能够进行调整的,也就是元素的数值可以从大变小。
#include<bits/stdc++.h>
using namespace std;
int num[];
bool cmp(int a,int b)
{
return a < b;
}
int main()
{
int n,ans;
while(cin>>n) {
for(int i = ;i < n; i++)
scanf("%d",&num[i]);
sort(num,num+n,cmp); //预处理,先把数组num从小到大排序
ans = ; //预设数组没有出现的最小整数是2
for(int i = ; i < n; i++)
{
if(ans <= num[i]) // 当目前的预设ans能够被覆盖时,更新ans
ans++;
}
cout<<ans<<endl;
}
return ;
}
CF | Alyona and Mex的更多相关文章
- 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 ...
- Codeforces 740C. Alyona and mex 思路模拟
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- 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 ...
- 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 ...
- CodeForces 682B Alyona and Mex (排序+离散化)
Alyona and Mex 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/B Description Someone gave ...
- Alyona and mex
Alyona and mex time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 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 ...
- Codeforces Round #381 (Div. 2)C Alyona and mex
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be ...
- B - Alyona and Mex
Description Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one oper ...
随机推荐
- Jenkins的安装
安装环境: 512M内存 10G硬盘空间 Java 8环境 先来创建jenkins的运行目录: mkdir /data/jenkins && cd /data/jenkins 下载je ...
- 使用 vue-i18n 切换中英文
兼容性: 支持 Vue.js 2.x 以上版本 安装方法:(此处只演示 npm) npm install vue-i18n 使用方法: 1.在 main.js 中引入 vue-i18n (前提是要先引 ...
- 九,微信小程序开发浅谈
最近在帮朋友做一款微信小程序(后面统称为小程序),有简单的交互,以及分享和支付功能.下面就简单的对小程序开发做一个简单的介绍,希望可以帮助大家!!! 当前的小程序我们是在windows系统里开发的,如 ...
- [LeetCode] Sum of Square Numbers 平方数之和
Given a non-negative integer c, your task is to decide whether there're two integers a and b such th ...
- c++类与对象(1)——构造,复制构造函数
CPP的类与对象: 当我们定义一个基本类型变量时,方法如下: int p; #定义一个int类型变量 bool b; #定义一个bool类型变量 float c ; #定义一个float类型变量 显然 ...
- Linux服务器断电导致挂载及xfs文件损坏的修复方法
系统文件损坏后进入紧急修复模式,无法进行维护工作 welcome to emergency mode!after logging in ,type "journalctl -xb" ...
- pyqt5 动画学习(四) 旋转动画,使用QGraphicsView让自己的控件旋转起来
今天学有所成,赶紧记下今天的成果 之前三篇文章分别演示了空间的大小改变,移动,及颜色变化.在后续研究旋转的过程中即为艰难 如果你是使用pyqt4,那么使用QGraphicsItemAnimation便 ...
- 【JDK1.8】JUC——LockSupport
一.前言 Basic thread blocking primitives for creating locks and other synchronization classes. 用于创建锁定和其 ...
- SSH执行hql报错:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]
报错信息: ERROR Dispatcher:38 - Exception occurred during processing request: user is not mapped [from u ...
- [HNOI2012]与非
题目描述 NAND(与非)是一种二元逻辑运算,其运算结果为真当且仅当两个输入的布尔值不全为真.NAND运算的真值表如下(1表示真,0表示假): 两个非负整数的NAND是指将它们表示成二进制数,再在对应 ...