liuziyang2010 @ 2024-07-08 09:11:16
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,k=0,a[100000]={};
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
cout<<a[k]<<endl;
return 0;
}
by GreenMelon @ 2024-07-08 09:17:02
把 a[100000]={} 改成 a[500005]={}
by GreenMelon @ 2024-07-08 09:17:33
不对,是 a[5000005]={}
@liuziyang2010
by zkz19853166298 @ 2024-07-08 09:19:55
#include<cstdio>
#include<iostream>
#define ll long long
using namespace std;
const int N=5*10e6+10;
ll n,a[N],b[N],k;
int m=1;
void merge(int l,int r){
if(l>=r) return;
int mid=(l+r)/2,cnt=l;
int i=l,j=mid+1;
while(i<=mid&&j<=r)
if(a[i]<=a[j]) b[cnt++]=a[i++];
else b[cnt++]=a[j++];
while(i<=mid) b[cnt++]=a[i++];
while(j<=r) b[cnt++]=a[j++];
for(m=l;m<=r;++m) a[m]=b[m];
}
void mergesort(int l,int r){
if(l>=r) return;
int mid=(l+r)/2;
mergesort(l,mid);
mergesort(mid+1,r);
merge(l,r);
}
int main(){
scanf("%lld%lld",&n,&k);
for(;m<=n;++m)
scanf("%lld",&a[m]);
mergesort(1,n);
printf("%lld",a[k+1]);
return 0;
}
by liuziyang2010 @ 2024-07-08 09:25:26
@GreenMelon 改了,变成TLE了
by GreenMelon @ 2024-07-08 09:29:51
cin>>n>>k;
改成 scanf("%d%d", &n, &k);
cin>>a[i]
改成 scanf("%d", &a[i]);
@liuziyang2010
by liuziyang2010 @ 2024-07-08 09:39:16
@GreenMelon A了,谢谢
by GreenMelon @ 2024-07-08 09:41:11
嗯呢