全RE求助

P1923 【深基9.例4】求第 k 小的数

Retribution321 @ 2024-11-21 17:53:50


#include<bits/stdc++.h>
using namespace std;
#define pzq(a,b,c) for(int a=b;a<c;a++)
#define maxn 10001

int main(){
    int n,k,a[maxn];
    cin>>n>>k;
    pzq(i,0,n)cin>>a[i];
    sort(a,a+n);
    unique(a,a+n);
    cout<<a[k];
    return 0;
}

by Retribution321 @ 2024-11-21 17:54:37

在本地运行正常,在洛谷上就不行了


by Retribution321 @ 2024-11-21 17:57:57

已知部分错误,改了常数,但一个WA两个TLE


by SunXiaolang @ 2024-11-21 17:59:48

@Retribution321你sort完可以直接输出了


by SunXiaolang @ 2024-11-21 18:00:39

#include<bits/stdc++.h>
using namespace std;
long long a[5000001];
int main(){
    int n,k,i;
    cin>>n>>k;
    for (i=0;i<n;i++){
        scanf ("%d",&a[i]);
    }
    sort (a,a+n);
    cout<<a[k];
}

@[Retribution321] 而且你要用格式化输入才能不TLE(luogu://user/1460836)


by Retribution321 @ 2024-11-21 18:02:47

@SunXiaolang不懂就问,怎样格式化输入呢?


by SunXiaolang @ 2024-11-21 18:04:46

@Retribution321看代码


by SunXiaolang @ 2024-11-21 18:05:16

@Retribution321会不会照葫芦画瓢


by Retribution321 @ 2024-11-21 18:06:29

@SunXiaolang就是scanf吗


by Retribution321 @ 2024-11-21 18:06:56

@SunXiaolang好的,谢谢


by SunXiaolang @ 2024-11-21 18:07:05

@Retribution321对


| 下一页