uses crt; const nm=100; Type td=array[1 nm] of byte; var x,y,L,a,a2:td; Max:word; chon:array[1 nm] of boolean; n,k,i,dd,count,count2:word; Procedure doc_tep; Var f: text; Begin assign(f,'ech.inp'); reset(f); readln(f,n,k); for i:=1 to n do readln(f,x[i],y[i],L[i]); close(f); End; procedure try(i:byte); var j:byte; Begin for j:=2 to n do if (dd>=k) and (not chon[j]) and ((((x[j]=x[a[i-1]]) and (y[j]>y[a[i-1]])) or ((y[j]=y[a[i-1]]) and (x[j]>x[a[i-1]])))) then begin a[i]:=j; dd:=dd+L[j]-k; count:=count+1; chon[j]:=true; if a[i]=n then Begin if Max<dd then begin max:=dd; a2:=a; count2:= count; end end else try(i+1); chon[j]:=false; dd:=dd-L[j]+k; count:=count-1; end; end; Procedure ghi_tep; Var f: text; Begin assign(f,'ech.out'); rewrite(f); writeln(f,max); writeln(f,count2); for i:=1 to count2 do writeln(f,x[a2[i]],' ',y[a2[i]]); close(f); End; Procedure thuc_hien; Begin Doc_tep; Max:=0; a[1]:=1; dd:=L[1]; count:=1; fillchar(chon,sizeof(chon),0); try(2); ghi_tep; End; Begin clrscr; thuc_hien; End. . chon[j]) and ((((x[j]=x[a[i-1]]) and (y[j]>y[a[i-1]])) or ((y[j]=y[a[i-1]]) and (x[j]>x[a[i-1]])))) then begin a[i]:=j; dd:=dd+L[j]-k; count:=count+1; chon[j]:=true;. a2:=a; count2:= count; end end else try(i+1); chon[j]:=false; dd:=dd-L[j]+k; count:=count-1; end; end; Procedure ghi_tep; Var f: text; Begin assign(f,'ech.out');