zoukankan      html  css  js  c++  java
  • 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 input
    output
    standard output

    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.

    Examples
    input
    5
    1 3 3 3 6
    output
    5
    input
    2
    2 1
    output
    3

    水题,一个数可以变成比他更小的数,问,使变完之后最大的mex数是多少。
    虽然现在感觉这是水题,但比赛的时候也就只能做出A,B两题。唉,能力还要提高啊,现在大一都差不多结束了,也就这水平。不知道搞ACM还有前途没但都已经进坑了,就不能放弃啊!
    话说换了一种打码的模板,感觉挺简洁的呢 ╭(╯^╰)╮
    #include<bits/stdc++.h>
    
    using namespace std;
    
    const int INF=0x3f3f3f3f;
    typedef long long ll;
    #define prN printf("
    ")
    #define PI(a) printf("%d
    ",a);
    #define SI(N) scanf("%d",&(N))
    #define SII(N,M) scanf("%d%d",&(N),&(M))
    #define cle(a,val) memset(a,(val),sizeof(a))
    #define rep(i,b) for(int i=0;i<(b);i++)
    #define Rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define reRep(i,a,b) for(int i=(a);i>=(b);i--)
    const double eps= 1e-9 ;
    
    /*  /////////////////////////     C o d i n g  S p a c e     /////////////////////////  */
    
    const int MAX_N= 100000+5 ;
    
    int a[MAX_N];
    int n;
    
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("C:\Users\Zmy\Desktop\in.txt","r",stdin);
    //    freopen("C:\Users\Zmy\Desktop\out.txt","w",stdout);
    #endif
        SI(n);
        rep(i,n)
        SI(a[i]);
        sort(a,a+n);
        int ans=1;
        Rep(i,0,n-1)
        {
            if (a[i]>=ans)
            {
                a[i]=ans;
                ans++;
            }
        }
        PI(ans);
        return 0;
    }
  • 相关阅读:
    库存回滚架构设计原则
    老人血脂高吃什么好
    旁边的旁边的旁边--纪念自己逝去的青春
    JAVA8 Map新方法:compute,computeIfAbsent,putIfAbsent与put的区别
    新晋总监生存指南终章——构建技术团队信息通道
    新晋总监生存指南五——人才运营机制,技术团队如何解决造血能力
    新晋总监生存指南四——项目执行指南,如何挽救混乱的项目
    新晋总监生存指南三——OKR,先进的管理工具
    新晋总监生存指南二——建立指标
    新晋总监生存指南开篇之总监二三事
  • 原文地址:https://www.cnblogs.com/s1124yy/p/5602075.html
Copyright © 2011-2022 走看看