Cod sursa(job #218600)

Utilizator andrici_cezarAndrici Cezar andrici_cezar Data 2 noiembrie 2008 19:02:58
Problema Loto Scor 5
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.53 kb
var f,g:text;
    n,m,i,s:longint;
    a:array[1..100]of longint;
begin
assign(f,'loto.in');reset(f);
assign(g,'loto.out');rewrite(g);
readln(f,n,m);
for i:=1 to n do
    read(f,a[i]);
s:=0;
while s<m do
begin
for i:=1 to n do
    if s+a[i]<=m then begin
                      s:=s+a[i];
                      write(g,a[i],' ');
                      if s=m then break;
                      end
    else break;
if s>m then begin
            write(g,-1);
            break;
            end;
end;
close(g);
end.