Luogu P2369 EXCEEDED WARNING A Solution

topic portal

Just use sort to sort the final output. But arrays are of type short int. Otherwise, it will exceed memory.

#include<bits/stdc++.h>
using namespace std;
int n,m;short int a[1000010];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=m;i++) printf("%d\n",a[i]);
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325321456&siteId=291194637