pascal qsort tle?

回复帖子 返回题目

@ CREED 2017-10-12 22:13
var
a:array[1..1000005]of longint;
i,n,m:longint;
procedure qsort(l,r:longint);
var
i,j,mid,t:longint;
begin
    i:=l;
    j:=r;
    mid:=a[(l+r) div 2];
    repeat
        while a[i]<mid do inc(i);
        while a[j]>mid do dec(j);
        if i<=j then
        begin
            t:=a[i];
            a[i]:=a[j];
            a[j]:=t;
            inc(i);
            dec(j);
        end;
    until i>j;
    if l<j then qsort(l,j);
    if i<r then qsort(i,r);
end;
begin
    readln(n,m);
    for i:=1 to n do
    read(a[i]);
    qsort(1,n);
    for i:=1 to m do
    writeln(a[i]);
end.