提交时间:2023-11-14 16:30:44
运行 ID: 110391
#include<bits/stdc++.h> using namespace std; int n,m,x; int a[100001],b[100001]; int bin(long long low,long long high) { int middle=(low+high)/2; if(x==a[middle]) return middle; else if(x<a[middle]) { high=middle-1; bin(low,high); } else if(x>a[middle]) { low=middle+1; bin(low,high); } } int main() { cin>>n>>m; for(int i=1;i<=n;i++) { cin>>a[i]; b[i]=a[i]; } sort(b+1,b+1+n); x=b[m]; cout<<bin(1,n)<<endl;; }