zoukankan      html  css  js  c++  java
  • Codeforces Round #631 (Div. 2) A. Dreamoon and Ranking Collection(水题)

    Dreamoon is a big fan of the Codeforces contests.

    One day, he claimed that he will collect all the places from 11 to 5454 after two more rated contests. It's amazing!

    Based on this, you come up with the following problem:

    There is a person who participated in nn Codeforces rounds. His place in the first round is a1a1 , his place in the second round is a2a2 , ..., his place in the nn -th round is anan .

    You are given a positive non-zero integer xx .

    Please, find the largest vv such that this person can collect all the places from 11 to vv after xx more rated contests.

    In other words, you need to find the largest vv , such that it is possible, that after xx more rated contests, for each 1iv1≤i≤v , there will exist a contest where this person took the ii -th place.

    For example, if n=6n=6 , x=2x=2 and a=[3,1,1,5,7,10]a=[3,1,1,5,7,10] then answer is v=5v=5 , because if on the next two contest he will take places 22 and 44 , then he will collect all places from 11 to 55 , so it is possible to get v=5v=5 .

    Input

    The first line contains an integer tt (1t51≤t≤5 ) denoting the number of test cases in the input.

    Each test case contains two lines. The first line contains two integers n,xn,x (1n,x1001≤n,x≤100 ). The second line contains nn positive non-zero integers a1,a2,,ana1,a2,…,an (1ai1001≤ai≤100 ).

    Output

    For each test case print one line containing the largest vv , such that it is possible that after xx other contests, for each 1iv1≤i≤v , there will exist a contest where this person took the ii -th place.

    Example
    Input
    Copy
    5
    6 2
    3 1 1 5 7 10
    1 100
    100
    11 1
    1 1 1 1 1 1 1 1 1 1 1
    1 1
    1
    4 57
    80 60 40 20
    
    Output
    Copy
    5
    101
    2
    2
    60
    第一次见这么啰嗦的A题(相比之下
    大意就是给一个序列,可能有重复数字,有x次机会为这个序列填上一个数字,问最终从里面获得的1~v连续子序列的v最大是多少。
    数据范围很小,先sort一遍,然后把长度为2的空缺区间用x补上,看最多能补到哪里。
    #include <bits/stdc++.h>
    using namespace std;
    int n,x,a[105];
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            cin>>n>>x;
            int i;
            for(i=1;i<=n;i++)scanf("%d",&a[i]);
            sort(a+1,a+n+1); 
            int cnt=0;
            a[n+1]=0x3f3f3f3f;//处理最后一位 因为有可能是1 1 1 1 1这样
            for(i=1;i<=n+1;i++)
            {
                int temp=a[i]-a[i-1];
                if(a[i]==a[i-1])continue;//重复跳过
                if(temp==1)
                {
                    cnt=a[i];//不需要动用x
                }
                else
                {
                    if(x>=temp-1)//能填上当前区间
                    {
                        cnt=a[i];
                        x-=(temp-1);
                    }
                    else//不能
                    {
                        cnt+=x;
                        break;
                    }
                }
             } 
             cout<<cnt<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Kubernetes 两步验证
    实战优化丨如何借助 CODING 实现云开发中的云函数的自动化部署
    弹性配置为构建提速
    一分钟开始持续集成之旅系列之:C 语言 + Makefile
    一分钟开始持续集成之旅系列之:Java + GWT
    静态网站架构的演进和最佳实践
    DevOps
    真香!CODING DevOps “极速构建计划”,再也不用担心构建慢了!
    CODING 敏捷实战系列课第二讲:Scrum 敏捷项目管理核心要素之 3355
    一分钟开始持续集成之旅系列之: Vue + 腾讯云 COS 上传部署
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12630718.html
Copyright © 2011-2022 走看看