# C. Less or Equal

C. Less or Equal

C.减少或平等

time limit per test: 2 seconds
time limit per test: 2 seconds

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

input: standard input
输入:标准输入

output: standard output
产出:标准产出

You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 109]
给你一个长度n和整数k的整数序列。你应该在[1;109]范围内打印任何整数x。

(ie.1≤x≤109) such that exactly k elements of given sequence are less than or equal to x.
(ie.1≤x≤109)使给定序列的精确k元素小于或等于x。

Note that the sequence can contain equal elements.
注意,序列可以包含相同的元素。

If there is no such x, print “-1” (without quotes).
如果没有这样的x,打印“-1”(没有引号)。

Input
输入

The first line of the input contains integer numbers n andk(1 < n≤2.10*,0< k< n). The second line of the input contains n
输入的第一行包含整数n和k(1<n≤2.10*,0<k<n)。输入的第二行包含n。

integer numbers a,a…,an(1≤ai≤109)- the sequence itelf.
整数a,a.,an(1≤ai≤109)-序列本身。

Output
输出量

Print any integer number x from range [1; 109] such that exactly k elements of given sequence is less or equal to x.
从范围[1;109]打印任意整数x,使给定序列中的k个元素小于或等于x。

If there is no such x, print “-1” (without quotes).
如果没有这样的x,打印“-1”(没有引号)。

模拟

int main( )
{
    int n,k;
    int a[200010];
    cin >> n >> k;

        for(int i = 0;i < n;++i)
            cin >> a[i];
        sort(a,a+n);
        if(k==n)cout << a[n-1] <<endl;
        else if(k==0){
            if(a[0] == 1)
                cout << "-1" <<endl;
            else
                cout << "1" <<endl;
        }
        else{
            if(a[k]>a[k-1])
                cout << a[k-1] << endl;
            else
                cout << "-1" <<endl;
        }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值