日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Less or Equal(CF-977C)

發(fā)布時間:2025/3/17 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Less or Equal(CF-977C) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem Description

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] (i.e. 1≤x≤10^9) such that exactly k elements of given sequence are less than or equal to x.

Note that the sequence can contain equal elements.

If there is no such x, print "-1" (without quotes).

Input

The first line of the input contains integer numbers nn and kk (1≤n≤2?10^5, 0≤k≤n). The second line of the input contains n integer numbers a1,a2,…,an (1≤ai≤10^9) — the sequence itself.

Output

Print any integer number x from range [1;109] such that exactly k elements of given sequence is less or equal to x.

If there is no such x, print "-1" (without quotes).

Examples

Input

7 4
3 7 5 1 10 3 20

Output

6

Input

7 2
3 7 5 1 10 3 20

Output

-1

題意: 給出 n 個數,求是否存在一個整數使得這個 n 個數中的 k 個數小于或等于這個整數,如果有這個整數,輸出這個整數,如果沒有,輸出 -1

思路:一開始以為用 sort 排序后直接輸出第 k 個即可,后來發(fā)現沒這么簡單,當 k 大于 1 或小于 n 時是可以的,但當 k 等于 1 或等于 n 時,情況就不同了,因此在 n 個數兩端,根據要求的[1,1e9],加上一個最大值與最小值,再 sort 排序即可。

Source Program

#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<cstdlib> #include<queue> #include<set> #include<map> #include<stack> #include<ctime> #include<vector> #define INF 0x3f3f3f3f #define PI acos(-1.0) #define N 1000005 #define MOD 1e9+7 #define E 1e-6 typedef long long ll; using namespace std; int a[N]; int main() {int n,k;cin>>n>>k;for(int i=1;i<=n;i++)cin>>a[i];a[0]=1;sort(a,a+n+1);a[n+2]=INF;if(a[k]==a[k+1])cout<<-1<<endl;elsecout<<a[k]<<endl;return 0; }

?

總結

以上是生活随笔為你收集整理的Less or Equal(CF-977C)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。