Run ID | Author | Problem | Lang | Verdict | Time | Memory | Code Length | Submit Time |
---|---|---|---|---|---|---|---|---|
31437 | lnx | 求第k大数 | C++ | Time Limit Exceeded | 1000 MS | 244 KB | 676 | 2023-11-18 19:32:47 |
#include<iostream> using namespace std; int f(int a[],int left,int right) { int temp=a[left]; while(left<right) { while(left<right&&a[right]>temp) right--; a[left]=a[right]; while(left<right&&a[left]>temp) left++; a[right]=a[left]; } a[left]=temp; return left; } int main() { int N,index,a[100001]; while(cin>>N>>index) { index=N-index; for(int i=0;i<N;i++) { cin>>a[i]; } int left=0,right=N-1; int pos=f(a,left,right); while(index!=pos) { if(pos<index) { pos=f(a,pos+1,right); } else if(pos>index) { pos=f(a,left,pos-1); } } cout<<a[pos]<<endl; } return 0; }