Cod sursa(job #157623)

Utilizator Clau2000GOREA CLAUDIU-CRISTIAN Clau2000 Data 13 martie 2008 10:10:49
Problema Semne Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 3.05 kb
var f,g:text;
    a,x:array[0..50000] of int64;
    n,i,j,k,i11,i12,i21,i22,i31,i32,i41,i42:WORD;
    s1,s,spoz,sneg:int64;
    gasit1,gasit2,gasit3,gasit4:boolean;
begin
     assign(f,'semne.in');
     assign(g,'semne.out');
     reset(f);
     rewrite(g);
     read(f,n,s);
     x[0]:=0;
     for j:=1 to n do
     begin
        read(f,a[j]);
        x[j]:=x[j-1]+a[j];
     end;
     for i:=1 to n do
        s1:=s1+a[i];
     a[0]:=-s;
     s1:=s1+a[0];
     if (s1 mod 2)=0 then
     begin
           spoz:=s1 div 2;
           sneg:=s1 div 2;
           if s>0 then sneg:=sneg-s
                   else spoz:=spoz-s;
           i:=0;
           gasit1:=false;
           gasit2:=false;
           gasit3:=false;
           gasit4:=false;
           repeat
                 i:=i+1;
                 if x[i]=spoz then
                 begin
                        i11:=1;
                        i12:=i;
                        gasit1:=true;
                 end
                 else
                 if x[i]=sneg then
                 begin
                      i21:=1;
                      i22:=i;
                      gasit2:=true;
                 end
                   else
                   begin
                        j:=i;
                        repeat
                                j:=j+1;
                                if x[j]-x[i]=spoz then
                                begin
                                     i31:=i+1;
                                     i32:=j;
                                     gasit3:=true;
                                end else
                                if x[j]-x[i]=sneg then
                                begin
                                     i41:=i+1;
                                     i42:=j;
                                     gasit4:=true;
                                end;

                        until gasit3 or gasit4;
                  end;
           until gasit1 or gasit2 or gasit3 or gasit4;
           if gasit1 then
           begin
                for k:=1 to i12 do
                        write(g,'+');
                for k:=i12+1 to n do
                        write(g,'-');
           end;
           if gasit2 then
           begin
                for k:=1 to i22 do
                        write(g,'-');
                for k:=i22+1 to n do
                        write(g,'+');
           end;
           if gasit3 then
           begin
                for k:=1 to i31-1 do
                        write(g,'-');
                for k:=i31 to i32 do
                        write(g,'+');
                for k:=i32+1 to n do
                        write(g,'-');
           end;
           if gasit4 then
           begin
                for k:=1 to i41-1 do
                        write(g,'+');
                for k:=i41 to i42 do
                        write(g,'-');
                for k:=i42+1 to n do
                        write(g,'+');
           end;

     end;
     close(f);
     close(g);
end.