Logovp1138 the k small integer, logovp1138

Source: Internet
Author: User

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 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.