ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1190. Bar of Chocolate

Why I got WA?Who can help me,please?Thanks.
Posted by wangchun 19 Jul 2003 13:53
var n:integer;
    sz:array[1..5000]of integer;
    lie:boolean;
procedure init;
var t,k:integer;
    c:char;
begin
     fillchar(sz,sizeof(sz),0);
     readln(n);
     for t:=1 to n do
         begin
              read(c);
              while c<>' ' do
                    read(c);
              read(k);
              if k=0 then
                 readln
                     else
                 readln(sz[t]);
         end;
end;
procedure make;
var t,k,v,l,m:integer;
begin
     lie:=false;
     v:=sz[n];
     k:=v;
     for t:=n-1 downto 1 do
         begin
              if sz[t]=0 then
                 k:=k+v
                         else
                 if sz[t]>v then
                    begin
                         k:=k+sz[t];
                         v:=sz[t];
                    end
                            else
                    begin
                         lie:=true;
                         break;
                    end;
         end;
     l:=k;
     if not lie then
        begin
             v:=sz[1];
             k:=v;
             for t:=2 to n do
                 begin
                      if sz[t]=0 then
                         inc(k,v)
                                 else
                         if sz[t]<v then
                            begin
                                 inc(k,v);
                                 v:=sz[t];
                            end
                                    else
                            begin
                                 lie:=true;
                                 break;
                            end;
                 end;
             m:=k;
             if not lie then
                begin
                     if not((l<=10000)and(m>=10000)) then
                        lie:=true;
                end;
        end;
end;
procedure print;
begin
     if lie then
        writeln('NO')
            else
        writeln('YES');
end;
begin
     init;
     make;
     print;
end.