fork download
  1. uses math;
  2. const fi='';
  3. fo='';
  4. maxn=300000;
  5. type arra=array[0..maxn] of longint;
  6. var tung,cuc,d,tu,cu:arra;
  7. kieu:array[0..maxn] of byte;
  8. i,j,n,a,b:longint;
  9. f:text;
  10. res,tmp:longint;
  11. procedure QS(l,r:longint);
  12. Var i,j,x,w:longint;
  13. Begin
  14. x:=d[(l+r) div 2];
  15. i:=l;j:=r;
  16. Repeat
  17. While(d[i]<x) do i:=i+1;
  18. While (x<d[j]) do j:=j-1;
  19. If i<=j then
  20. Begin
  21. w:=kieu[i];kieu[i]:=kieu[j];kieu[j]:=w;
  22. w:=d[i];d[i]:=d[j];d[j]:=w;
  23. i:=i+1;j:=j-1;
  24. End;
  25. until i>j;
  26. If l<j then QS(l,j);
  27. If i<r then QS(i,r);
  28. End;
  29. procedure nhap;
  30. begin
  31. assign(f,fi);
  32. reset(f);
  33. readln(f,n,a,b);
  34. for i:=1 to n do
  35. readln(f,d[i],kieu[i]);
  36. close(f);
  37. end;
  38. procedure xuly;
  39. var t,c,k:longint;
  40. begin
  41. t:=0; c:=0;
  42. qs(1,n);
  43. for i:=1 to n do
  44. if kieu[i]=1 then begin inc(t); tung[t]:=i; end
  45. else begin inc(c); cuc[c]:=i; end;
  46. for i:=1 to n do
  47. begin
  48. tu[i]:=tu[i-1];
  49. cu[i]:=cu[i-1];
  50. if kieu[i]=1 then inc(tu[i]);
  51. if kieu[i]=2 then inc(cu[i]);
  52. end;
  53. if (tu[n]<a) or(cu[n]<b) then exit;
  54. i:=max(tung[a],cuc[b]);
  55. k:=min(tung[tu[i]-a+1],cuc[cu[i]-b+1]);
  56. res:=d[i]-d[k];
  57. inc(i);
  58. while i<=n do
  59. begin
  60. tmp:=min(tung[tu[i]-a+1],cuc[cu[i]-b+1]);
  61. if d[i]-d[tmp]<res then res:=d[i]-d[tmp];
  62. inc(i);
  63. end;
  64. end;
  65. procedure xuat;
  66. begin
  67. assign(f,fo);
  68. rewrite(f);
  69. if res=0 then writeln(f,-1) else
  70. writeln(f,res);
  71. close(f);
  72. end;
  73. begin
  74. nhap;
  75. xuly;
  76. xuat;
  77. end.
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class, interface, or enum expected
uses    math;
^
Main.java:2: error: class, interface, or enum expected
const   fi='';
^
Main.java:2: error: empty character literal
const   fi='';
           ^
Main.java:2: error: unclosed character literal
const   fi='';
            ^
Main.java:3: error: empty character literal
        fo='';
           ^
Main.java:3: error: unclosed character literal
        fo='';
            ^
Main.java:5: error: class, interface, or enum expected
type    arra=array[0..maxn] of longint;
^
Main.java:6: error: class, interface, or enum expected
var     tung,cuc,d,tu,cu:arra;
^
Main.java:7: error: class, interface, or enum expected
        kieu:array[0..maxn] of byte;
        ^
Main.java:8: error: class, interface, or enum expected
        i,j,n,a,b:longint;
        ^
Main.java:9: error: class, interface, or enum expected
        f:text;
        ^
Main.java:10: error: class, interface, or enum expected
        res,tmp:longint;
        ^
Main.java:11: error: class, interface, or enum expected
procedure QS(l,r:longint);
^
Main.java:12: error: class, interface, or enum expected
Var i,j,x,w:longint;
^
Main.java:13: error: class, interface, or enum expected
Begin
^
Main.java:15: error: class, interface, or enum expected
  i:=l;j:=r;
  ^
Main.java:15: error: class, interface, or enum expected
  i:=l;j:=r;
       ^
Main.java:16: error: class, interface, or enum expected
  Repeat
  ^
Main.java:18: error: class, interface, or enum expected
     While (x<d[j]) do j:=j-1;
     ^
Main.java:19: error: class, interface, or enum expected
      If i<=j then
      ^
Main.java:21: error: class, interface, or enum expected
          w:=kieu[i];kieu[i]:=kieu[j];kieu[j]:=w;
                     ^
Main.java:21: error: class, interface, or enum expected
          w:=kieu[i];kieu[i]:=kieu[j];kieu[j]:=w;
                                      ^
Main.java:22: error: class, interface, or enum expected
          w:=d[i];d[i]:=d[j];d[j]:=w;
          ^
Main.java:22: error: class, interface, or enum expected
          w:=d[i];d[i]:=d[j];d[j]:=w;
                  ^
Main.java:22: error: class, interface, or enum expected
          w:=d[i];d[i]:=d[j];d[j]:=w;
                             ^
Main.java:23: error: class, interface, or enum expected
          i:=i+1;j:=j-1;
          ^
Main.java:23: error: class, interface, or enum expected
          i:=i+1;j:=j-1;
                 ^
Main.java:24: error: class, interface, or enum expected
        End;
        ^
Main.java:25: error: class, interface, or enum expected
 until i>j;
 ^
Main.java:26: error: class, interface, or enum expected
 If l<j then QS(l,j);
 ^
Main.java:27: error: class, interface, or enum expected
 If i<r then QS(i,r);
 ^
Main.java:28: error: class, interface, or enum expected
End;
^
Main.java:29: error: class, interface, or enum expected
procedure nhap;
^
Main.java:30: error: class, interface, or enum expected
begin
^
Main.java:32: error: class, interface, or enum expected
    reset(f);
    ^
Main.java:33: error: class, interface, or enum expected
    readln(f,n,a,b);
    ^
Main.java:34: error: class, interface, or enum expected
    for i:=1 to n do
    ^
Main.java:36: error: class, interface, or enum expected
    close(f);
    ^
Main.java:37: error: class, interface, or enum expected
end;
^
Main.java:38: error: class, interface, or enum expected
procedure xuly;
^
Main.java:39: error: class, interface, or enum expected
var     t,c,k:longint;
^
Main.java:40: error: class, interface, or enum expected
begin
^
Main.java:41: error: class, interface, or enum expected
    t:=0; c:=0;
          ^
Main.java:42: error: class, interface, or enum expected
    qs(1,n);
    ^
Main.java:43: error: class, interface, or enum expected
    for i:=1 to n do
    ^
Main.java:44: error: class, interface, or enum expected
        if kieu[i]=1 then begin inc(t); tung[t]:=i; end
                                        ^
Main.java:44: error: class, interface, or enum expected
        if kieu[i]=1 then begin inc(t); tung[t]:=i; end
                                                    ^
Main.java:45: error: class, interface, or enum expected
        else begin inc(c); cuc[c]:=i; end;
                           ^
Main.java:45: error: class, interface, or enum expected
        else begin inc(c); cuc[c]:=i; end;
                                      ^
Main.java:46: error: class, interface, or enum expected
    for i:=1 to n do
    ^
Main.java:49: error: class, interface, or enum expected
        cu[i]:=cu[i-1];
        ^
Main.java:50: error: class, interface, or enum expected
        if kieu[i]=1 then inc(tu[i]);
        ^
Main.java:51: error: class, interface, or enum expected
        if kieu[i]=2  then inc(cu[i]);
        ^
Main.java:52: error: class, interface, or enum expected
    end;
    ^
Main.java:53: error: class, interface, or enum expected
if (tu[n]<a) or(cu[n]<b) then exit;
^
Main.java:54: error: class, interface, or enum expected
    i:=max(tung[a],cuc[b]);
    ^
Main.java:55: error: class, interface, or enum expected
    k:=min(tung[tu[i]-a+1],cuc[cu[i]-b+1]);
    ^
Main.java:56: error: class, interface, or enum expected
    res:=d[i]-d[k];
    ^
Main.java:57: error: class, interface, or enum expected
    inc(i);
    ^
Main.java:58: error: class, interface, or enum expected
    while i<=n do
    ^
Main.java:61: error: class, interface, or enum expected
        if d[i]-d[tmp]<res then res:=d[i]-d[tmp];
        ^
Main.java:62: error: class, interface, or enum expected
        inc(i);
        ^
Main.java:63: error: class, interface, or enum expected
    end;
    ^
Main.java:64: error: class, interface, or enum expected
end;
^
Main.java:65: error: class, interface, or enum expected
procedure xuat;
^
Main.java:66: error: class, interface, or enum expected
begin
^
Main.java:68: error: class, interface, or enum expected
    rewrite(f);
    ^
Main.java:69: error: class, interface, or enum expected
    if res=0 then writeln(f,-1) else
    ^
Main.java:71: error: class, interface, or enum expected
    close(f);
    ^
Main.java:72: error: class, interface, or enum expected
end;
^
Main.java:73: error: class, interface, or enum expected
begin
^
Main.java:75: error: class, interface, or enum expected
    xuly;
    ^
Main.java:76: error: class, interface, or enum expected
    xuat;
    ^
Main.java:77: error: class, interface, or enum expected
end.
^
74 errors
stdout
Standard output is empty