[1138] k-Luo Gu small integers

Title Description

Conventional n n positive integer, n≤10000 n . 1 0 0 0 0, the requirement that n of n positive integers K K smallest integer (an integer equal size are counted only once), k≤1000 K . 1 0 0 0 positive integer less than 30000 . 3 0 0 0 0

Input Format

The first line n- n-and K K; for the second line n- n-n-integer values, separated by a space between the integer.

Output Format

Of K K is the smallest integer value; if no solution, then output "NO RESULT".

Sample input and output

Input # 1
10 3
1 3 3 7 2 5 1 2 4 6
Output # 1
3

Description / Tips

n≤10000n10000

 

Solution: Red question really fragrant (do not want to write the solution to a problem, too mentally handicapped)

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<bits/stdc++.h>
using namespace std;
int n,k,a[10004],tot,flag;
int main(){
    freopen("1138.in","r",stdin);
    freopen("1138.out","w",stdout);
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++){
        if(a[i]!=a[i+1]) tot++;
        if(tot==k) {
            cout<<a[i]; flag=1; break;
        }
    }
    if(flag==0) cout<<"NO RESULT";
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/wuhu-JJJ/p/11857908.html