xiaozqh
[srcbox.git] / rqnoj / rqnoj22.pas
blobd739616715f55e990f84db5addd36acce749e515
1 var
2 n,k,i,j,l:longint;
3 a:array [0..10000] of longint;
5 begin
6 readln(n,k);
7 for i:=1 to n do read(a[i]);
8 for i:=1 to k do
9 begin
10 j:=n-1;
11 while (j>0) and (a[j]>a[j+1]) do dec(j);
12 if j=0 then
13 begin
14 for j:=1 to n do a[j]:=j;
15 continue;
16 end;
17 for l:=n downto j+1 do
18 if (a[l]>a[j]) then break;
19 a[0]:=a[j]; a[j]:=a[l]; a[l]:=a[0];
20 for l:=j+1 to (n+j+1) div 2 do
21 begin
22 a[0]:=a[l]; a[l]:=a[n-l+j+1]; a[n-l+j+1]:=a[0];
23 end;
24 end;
25 write(a[1]);
26 for i:=2 to n do write(' ',a[i]);
27 end.