Cod sursa(job #179598)

Utilizator nightwachComanescu Mircea nightwach Data 16 aprilie 2008 09:48:21
Problema Loto Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.49 kb
type vect=array[0..100] of longint;
var f:text;
    i,l,j,k,n,x,y:integer;
    s,s2:longint;
    v:vect;
    a:^vect;
begin
assign(f,'loto.in');
reset(f);
readln(f,n,s);
for i:=0 to n-1 do read(f,v[i]);
l:=0;
new(a);
for i:=0 to n-1 do
        for j:=i to n-1
         do for k:=j to n-1 do begin
                a^[l]:=v[i]+v[j]+v[k];
                inc(l);
                end;
k:=1;
for i:=0 to l-1 do
        if k=1 then begin
        for j:=i to l-1 do
                if k=1 then begin
                if s=a^[i]+a^[j] then k:=0;end
                else break
                end
                else break;



close(f);
assign(f,'loto.out');
rewrite(f);
dec(i);
if k=1 then writeln(f,'-1')
else begin
for k:=0 to n-1 do
        if i<>-1 then
        for x:=k to n-1 do
                if i<>-1 then
                for y:=x to n-1 do
                if i<>-1 then
                        if a^[i]=v[k]+v[x]+v[y] then begin
                                write(f,v[k],' ',v[x],' ',v[y],' ');
                                i:=-1;
                                end;
for k:=0 to n-1 do
        if j<>-1 then
        for x:=k to n-1 do
                if j<>-1 then
                for y:=x to n-1 do
                if j<>-1 then
                        if a^[j]=v[k]+v[x]+v[y] then begin
                                write(f,v[k],' ',v[x],' ',v[y],' ');
                                j:=-1;
                                end;
end;
close(f);
end.