Cod sursa(job #78095)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 15 august 2007 15:30:36
Problema Semne Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.88 kb
program p1;
var f,f1:text;
    n,i,q:1..50000;
    w:0..1;
    s1,s:longint;
    a:array[1..12500]of longint;
    c:array[1..12500]of 0..1;
begin
assign(f,'semne.in');reset(f);
readln(f,n,s);
for i:=1 to n do
    read(f,a[i]);
for i:=1 to n-1 do
    c[i]:=0;
c[n]:=1;
w:=0;
repeat
s1:=0;
for i:=1 to n do
    if c[i]=0 then s1:=s1+a[i]
              else s1:=s1-a[i];
if s1=s then begin
             w:=1;
             for i:=1 to n do
                 if c[i]=0 then write(f,'+')
                           else write(f,'-');
             end;
if c[n]=0 then c[n]:=1
          else begin
               q:=n;
               while c[q]=1 do
                     begin
                     c[q]:=0;
                     q:=q-1;
                     end;
               c[q]:=1;
               end;
until w=1;
assign(f,'semne.out');rewrite(f);
close(f);
end.