1 program wonder;
2 const
3 inf=‘minval.in‘;
4 outf=‘minval.out‘;
5 var
6 len,i,j,n,tmp,ans,m:longint;
7 heap,w,a,b,c,name:array[0..10000] of longint;
8
9 procedure swap(var aa,bb:longint);
10 var t:longint;
11 begin
12 t:=aa; aa:=bb; bb:=t;
13 end;
14
15 procedure insert(tmp:longint);
16 var
17 i:longint;
18 begin
19 inc(len);
20 heap[len]:=tmp; name[len]:=len;
21 i:=len;
22 while (i>1) and (heap[i div 2]>heap[i]) do
23 begin
24 swap(heap[i],heap[i div 2]);
25 swap(name[i],name[i div 2]);
26 i:=i div 2;
27 end;
28 end;
29
30 procedure ch;
31 var
32 dad,son:longint;
33 stop:boolean;
34 begin
35 write(heap[1],‘ ‘);
36 inc(w[name[1]]);
37 heap[1]:=w[name[1]]*w[name[1]]*a[name[1]]+w[name[1]]*b[name[1]]+c[name[1]];
38 dad:=1;
39 stop:=false;
40 while ((dad*2+1<=len) or (dad*2<=len)) and (not stop) do
41 begin
42 if (heap[dad*2+1]>heap[dad*2]) or (dad*2+1>len) then
43 son:=dad*2
44 else son:=dad*2+1;
45 if heap[dad]<=heap[son] then stop:=true
46 else begin
47 swap(heap[dad],heap[son]);
48 swap(name[dad],name[son]);
49 dad:=son; //!!!!
50 end;
51 end;
52 end;
53
54 begin
55 assign(input,inf); assign(output,outf);
56 reset(input); rewrite(output);
57
58 readln(n,m);
59 for i:= 1 to n do
60 begin
61 read(a[i],b[i],c[i]);
62 tmp:=a[i]+b[i]+c[i];
63 w[i]:=1;
64 insert(tmp);
65 end;
66
67 for i:= 1 to m do ch;
68
69 close(input); close(output);
70 end.