十分求助 不知道哪错了
查看原帖
十分求助 不知道哪错了
819273
LIUYC_C楼主2023/3/10 08:01

时间复杂度如果是枚举高度的话<1e9

#include <bits/stdc++.h>
using namespace std;
const int N=1010;
typedef long long LL;
int main(){
    LL n,high;
    unordered_map<LL,LL> hash;
    cin>>n>>high;
    LL maxl=-1e9;
    for(int i=1;i<=n;i++){
        LL x;
        scanf("%lld",&x);
        hash[x]++;
        maxl=max(maxl,x);
    }
    LL temp=0,ans=0,res;
   for(int i=maxl;i>=1;i--){
        ans+=temp;
        if(hash[i]) temp+=hash[i];
        if(ans==high){
            res=i;
            break;
        } 
    }
    cout<<res;
    return 0;
}
2023/3/10 08:01
加载中...