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 Wa 12?
Posted by Rabidstorm 7 Feb 2009 08:15
program Ural1190;

var
  h:array[1..5000]of longint;
  a,can,n,l,m:longint;
  w:char;

begin
  readln(n);
  fillchar(h,sizeof(h),0);
  l:=maxlongint;
  for a:=1 to n do
    begin
      w:='a';
      while w<>' ' do
        read(w);
      read(m);
      if m=1 then
      readln(h[a])
      else h[a]:=-1;
    end;
  l:=1;
  can:=0;
  for a:=1 to n do
    begin
      if h[a]=-1 then inc(l);
      if h[a]<>-1 then
      begin
        can:=can+h[a]*l;
        l:=1;
      end;
    end;
  if can>10000 then
  begin
    writeln('NO');
    halt;
  end;
  can:=0;
  l:=1;
  for a:=n downto 1 do
    begin
      if h[a]=-1 then inc(l);
      if h[a]<>-1 then
      begin
        can:=can+h[a]*l;
        l:=1;
      end;
    end;
    if l>1 then can:=can+10000;
    if can<10000 then
    begin
      writeln('NO');
      halt;
    end;
  writeln('YES');
end.

Edited by author 07.02.2009 08:15

Edited by author 07.02.2009 08:15