大佬求教,为什么超时

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

wuyu6688 @ 2024-04-30 21:47:12

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[5000001] , b , c;
    cin >> b >> c;
    for(int i = 0; i < b; i++)
    {
        cin >> a[i];
    }
    sort(a , a + b);
    cout << a[c] <<endl;
    return 0;
}

by Ame_wiki @ 2024-04-30 21:55:30

还有你数组这么定义不炸吗(虽然我没试过)


by keep_shining @ 2024-04-30 22:04:48


#include<bits/stdc++.h>

using namespace std;

int n,k,a[5000000];

int main()

{

    cin>>n>>k;

    for(int i=1;i<=n;i++)

    {

        scanf("%d",&a[i]);

    }

    sort(a,a+n);

    cout<<a[k];

    return 0;

}

by WaTleZero_pt @ 2024-04-30 22:13:53

牛,5e6 个数用 cin 读入!!!

再说了这题 sort 不会炸?


by WZwangchongming @ 2024-05-02 14:55:09

@WaTleZero_pt sort可以卡过


|