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 1140. Swamp Incident

what's wrong?
Posted by Edric Mao 2 Sep 2010 16:39
program ural;
uses math;
var s:array['X'..'Z']of integer;
    c:char;
    d,n,i:integer;
begin
  readln(n);
  for i:=1 to n do
    begin
      read(c);
      readln(d);
      s[c]:=s[c]+d;
    end;
  if(s['X']>0)and(s['Z']>0)then
    begin
      d:=min(s['X'],s['Z']);
      inc(s['Y'],d);
      dec(s['X'],d);
      dec(s['Z'],d);
    end
  else
    if(s['X']<0)and(s['Z']<0)then
      begin
        d:=max(s['X'],s['Z']);
        inc(s['Y'],d);
        dec(s['X'],d);
        dec(s['Z'],d);
      end;
  if(s['X']>0)and(s['Y']<0)then
    begin
      d:=max(-s['X'],s['Y']);
      inc(s['Z'],d);
      inc(s['X'],d);
      dec(s['Y'],d);
    end
  else
    if(s['X']<0)and(s['Y']>0)then
      begin
        d:=min(-s['X'],s['Y']);
        inc(s['Z'],d);
        inc(s['X'],d);
        dec(s['Y'],d);
      end;
  if(s['Z']>0)and(s['Y']<0)then
    begin
      d:=max(-s['Z'],s['Y']);
      inc(s['X'],d);
      inc(s['Z'],d);
      dec(s['Y'],d);
    end
  else
    if(s['Z']<0)and(s['Y']>0)then
      begin
        d:=min(-s['Z'],s['Y']);
        inc(s['X'],d);
        inc(s['Z'],d);
        dec(s['Y'],d);
      end;
  writeln(abs(s['X'])+abs(s['Y'])+abs(s['Z']));
  if s['X']<>0 then
    writeln('X ',-s['X']);
  if s['Y']<>0 then
    writeln('Y ',-s['Y']);
  if s['Z']<>0 then
    writeln('Z ',-s['Z']);
end.