about summary refs log tree commit diff
path: root/10/lập-lịch/ctmt.pas
blob: bdd30f03cf7f4cc828c237108d049f8108f28bc0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const
  inp = 'ctmt.inp';
  out = 'ctmt.out';
type
  int200 = 1..200;
  intday = 0..8640000;
var
  f : text;
  n, i, j, ln2, ln3 : int200;
  a, b : array[1..200] of intday;
  p, q, r, s , max0, max1 : intday;
  ln0, ln1 : 0..1;
procedure swab(i0, j0 : int200);
  var tmp : intday;
  begin
    tmp := a[i0];
    a[i0] := a[j0];
    a[j0] := tmp;
    tmp := b[i0];
    b[i0] := b[j0];
    b[j0] := tmp
  end;
procedure del(m : int200);
  var o : int200;
  begin
    dec(n);
    for o := m to n do
      begin
        a[o] := a[o + 1];
        b[o] := b[o + 1]
      end
  end;
begin
  assign(f, inp);
  reset(f);
  readln(f, n);
  for i := 1 to n do
    readln(f, a[i], b[i]);
  readln(f, p, q);
  readln(f, r, s);
  close(f);
  for i := 1 to n - 1 do
    for j := i + 1 to n do
      if a[i] > a[j] then swab(i, j);
  i := 1;
  while i < n do
    begin
      j := i + 1;
      while j <= n do
        begin
          if (a[j] <= b[i]) and (b[i] <= b[j]) then
            begin
              b[i] := b[j];
              del(j)
            end
          else inc(j)
        end;
      inc(i)
    end;
  ln0 := 0;
  ln1 := 0;
  max0 := 0;
  max1 := 0;
  for i := 1 to n do
    begin
      if (a[i] <= p) and (q <= b[i]) then ln0 := 1;
      if (i < n) and (b[i] < r) and (s < a[i + 1]) then ln1 := 1;
      if b[i] - a[i] >= max0 then
        begin
          ln2 := i;
          max0 := b[i] - a[i]
        end;
      if (i < n) and (a[i + 1] - b[i] > max1) then
        begin
          ln3 := i;
          max1 := a[i + i] - b[i]
        end
    end;
  assign(f, out);
  rewrite(f);
  writeln(f, ln0);
  writeln(f, ln1);
  writeln(f, a[ln2], ' ', b[ln2]);
  writeln(f, b[ln3] + 1, ' ', a[ln3 + 1] - 1);
  close(f)
end.