Logovp1138 the k small integer, logovp1138
Description
There are n positive integers, n ≤ 10000. The minimum k integer in the n positive integers (Integers of the same size are calculated only once), k ≤ 1000, and all positive integers are less than 30000.
Input/Output Format
Input Format:
The first line is n and k. The second line starts with the values of n positive integers, which are separated by spaces.
Output Format:
The value of the minimum integer at k. If NO solution is available, "no result" is output ".
Input and Output sample input sample #1: Copy
10 31 3 3 7 2 5 1 2 4 6
Output example #1: Copy
3
Description
N ≤ 10000
Hurt by unique
This item returns the number of elements in the deduplicated array.
So if you want to get the address of the last element, You have to-1.
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #include<deque> 7 #define LL long long 8 #define lb(x) ((x)&(-x)) 9 using namespace std;10 const int MAXN=1000001;11 inline int read()12 {13 char c=getchar();int x=0,f=1;14 while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}15 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*f;16 }17 int n;18 int a[MAXN];19 int main()20 {21 int n=read(),k=read();22 for(int i=1;i<=n;i++) a[i]=read();23 sort(a+1,a+n+1);24 int pos=unique(a+1,a+n+1)-a-1;25 if(k<=pos) printf("%d",a[k]);26 else printf("NO RESULT");27 return 0;28 }