Cod sursa(job #45632)

Utilizator floringh06Florin Ghesu floringh06 Data 1 aprilie 2007 19:10:51
Problema Semne Scor 15
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.14 kb
{$IFDEF NORMAL}
  {$I-,Q-,R-,S-}
{$ENDIF NORMAL}
{$IFDEF DEBUG}
  {$I+,Q+,R+,S-}
{$ENDIF DEBUG}
{$IFDEF RELEASE}
  {$I-,Q-,R-,S-}
{$ENDIF RELEASE}


var fi,fo:text;
    i,n,s:longword;
    a:array[1..500002] of longint;
    sol:array[1..500002] of char;


  procedure go_solve;
   var i,j:word;
       sum:longint;
       solf:boolean;
      bulan:longint;
  begin
   solf:=false;
   while not (solf) do
   begin
   sum:=0;
   for i:=1 to n do
    begin
    randomize;
    if sum<s then
     begin sum:=sum+a[i]; sol[i]:='+'; continue; end;
    if sum>s then
     begin sum:=sum-a[i]; sol[i]:='-'; continue; end;
    if (sum=s) then
     begin
     bulan:=random(666013);
     if bulan mod 2=0 then
       begin sum:=sum+a[i]; sol[i]:='+'; continue; end
     else
       begin sum:=sum-a[i]; sol[i]:='-'; continue; end;
     end;
    end;
   if sum=s then solf:=true; //am bulan
   end;
  end;





begin
assign(fi,'semne.in'); reset(fi);
assign(fo,'semne.out'); rewrite(fo);
readln(fi,n,s);
for i:=n downto 1 do
begin
 read(fi,a[i]);
end;
go_solve;
for i:=n downto 1 do
 write(fo,sol[i]);
close(fo);
end.