Pagini recente » Cod sursa (job #2646153) | Cod sursa (job #45636)
Cod sursa(job #45636)
{$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:longint;
a:array[1..500002] of longint;
sol:array[1..500002] of char;
procedure go_solve;
var i,j:longint;
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(13);
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.