Pagini recente » Cod sursa (job #857496) | Cod sursa (job #1007378) | Cod sursa (job #3210550) | Cod sursa (job #1466128) | Cod sursa (job #771174)
Cod sursa(job #771174)
Program semne;
var a,plus,minus,sol:array [0..50005] of longint;
i,n,p,m,aux,pos:longint;
sc,s:int64;
ok:boolean;
fi,fo:text;
procedure cauta(val:longint);
var l,r,mid:longint;
begin
pos:=-1; l:=1; r:=n;
while (pos=-1) and (l<=r) do begin
mid:=(l+r) div 2;
if a[mid]>val then r:=mid-1
else if a[mid]<val then l:=mid+1
else pos:=mid;
end;
end;
begin
assign(fi,'semne.in');
assign(fo,'semne.out');
reset(fi); rewrite(fo); readln(fi,n,s); sc:=0;
for i:=1 to n do begin
read(fi,a[i]);
aux:=random(2);
if aux=0 then begin inc(m); sc:=sc-a[i]; minus[m]:=a[i]; end
else begin inc(p); sc:=sc+a[i]; plus[p]:=a[i]; end;
end;
while sc<>s do
if sc<s then begin
aux:=random(m)+1;
inc(p); plus[p]:=minus[aux];
sc:=sc+2*minus[aux];
minus[aux]:=minus[m]; dec(m);
end
else if sc>s then begin
aux:=random(p)+1;
inc(m); minus[m]:=plus[aux];
sc:=sc-2*plus[aux];
plus[aux]:=plus[p]; dec(p);
end;
for i:=1 to m do begin cauta(minus[i]); sol[pos]:=1; end;
for i:=1 to n do
if sol[i]=1 then write(fo,'-') else write(fo,'+');
if sc=s then close(fo);
end.