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 1116. Piecewise Constant Function

what is test 8?! I've tried all the tests in the forum but still be WA on test 8.....Can any one help me ???
Posted by FailedWing 28 Oct 2005 10:45
  var
    n, m    : longint;
    s, g, f : array[1..30000] of record
                      x, y, value : longint;
                    end;

  procedure init;
    var
    i : longint;
    begin
      read(n);
      for i := 1 to n do
        begin
          read(f[i].x, f[i].y, f[i].value);
          dec(f[i].y);
        end;
      readln;
      read(m);
      for i := 1 to m do
        begin
          read(g[i].x, g[i].y, g[i].value);
          dec(g[i].y);
        end;
      readln;
    end;

  function max(a, b : longint) : longint;
    begin
          if a > b
            then max := a
            else max := b;
    end;

  procedure make;
    var
    i, j, n1 : longint;
    begin
          i := 1;
      while i <= n do
        begin
          for j := 1 to m do
            begin
          if g[j].x > f[i].y
            then break;
                  if g[j].x <= f[i].x
                    then f[i].x := max(f[i].x, g[j].y + 1)
                    else if (g[j].x <= f[i].y) and (g[j].y >= f[i].y)
                          then f[i].y := g[j].x - 1
              else begin
                inc(n);
                f[n].x := g[j].y + 1;
                f[n].y := f[i].y;
                            f[n].value := f[i].value;
                            f[i].y := g[j].x - 1;
              end;
                  if f[i].x > f[i].y
                    then break;
        end;
                inc(i);
        end;
    end;

  procedure print;
    var
    i, total : longint;
    begin
      total := 0;
      total := 0;
      for i := 1 to n do
        if f[i].x <= f[i].y
          then inc(total);
          write(total, ' ');
      for i := 1 to total do
            if f[i].x <= f[i].y
          then write(f[i].x, ' ', f[i].y + 1, ' ', f[i].value, ' ');
      writeln;
    end;

  begin
        while not eof do begin
    init;
    make;
    print;
        end;
  end.