测试点1是没有相同元素的;其他错的点也是。
看看样例与测试点一的区别:
样例:
10 3
1 3 3 7 2 5 1 2 4 6
测试点1:
10 3
6 37 40 44 52 73 94 82 89 63
代码:
#include<bits/stdc++.h>
using namespace std;
int a[10001];
int main()
{
int n,k,x=0;a[0]=100000;
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<n;i++)
{
int max=i+1;
for(int j=i+1;j<=n;j++)
{
if(a[j]<a[max])max=j;
}
swap(a[i],a[max]);
}
for(int i=1;i<=n;i++)
{
if(a[i]!=a[i-1])x++;
if(x==k){
cout<<a[i];
return 0;
}
}
cout<<"NO RESULT";
return 0;
}
求指导