Cod sursa(job #158629)

Utilizator Vlad-andreiVlad Fisca Vlad-andrei Data 13 martie 2008 18:52:56
Problema Semne Scor 15
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.63 kb
var f,g:text;
    a,x:array[0..50000] of longint;
    n,i,j,k,i11,i12,i21,i22,i31,i32,i41,i42:longint;
    s1,s,spoz,sneg:longint;
    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;
     a[0]:=-s;
     s1:=X[N]-s;
     if s1 mod 2=0 then
     begin
     spoz:=s1 div 2;
     sneg:=s1 div 2;
    { if s>0 then spoz:=sneg+s
        else spoz:=spoz+s;}
     spoz:=spoz+s;
     i:=1;
     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 or (j=n);
              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.