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 1169. Pairs

I need help very much...
Posted by 198808xc 6 Jul 2005 08:40
Program is Here:

 Program Ural1169(Input,Output);
 Const
      MaxN=100;
 Type
      IntTypeNum1=Longint;
      IntTypeNum3=Shortint;
      SolutionType=array [1..MaxN] of IntTypeNum1;
 Var
      n,k,Total:IntTypeNum1;
      Found:Boolean;
      Sol:SolutionType;
 Procedure Init;
    begin
      readln(n,k);
    end;
 Procedure Search(Left,Need:IntTypeNum1);
    var
      l,Temp:IntTypeNum1;
    begin
      if Need=0 then
        begin
          Found:=True;
          Exit;
        end;
      if Left*(Left-1) div 2<Need then Exit;
      for l:=3 to Left do
        begin
          Temp:=l*(l-1) div 2;
          inc(Total);
          Sol[Total]:=l;
          if Need>=Temp then Search(Left-l,Need-Temp)
            else
              begin
                dec(Total);
                Break;
              end;
          if Found then Exit;
          dec(Total);
        end;
    end;
 Procedure Main;
    var
      i,L1,L2,Cur:IntTypeNum1;
    begin
      if (n=1) and (k=0) then Exit;
      if n=2 then
        begin
          if k=0 then writeln(-1);
          if k=1 then writeln(1,' ',2);
          Exit;
        end;
      Found:=False;
      Total:=0;
      Search(n,n*(n-1) div 2-k);
      if not Found then
        begin
          writeln(-1);
          Exit;
        end;
      Cur:=0;
      for i:=1 to Total do
        begin
          if i<>1 then writeln(1,' ',Cur+1);
          for L1:=Cur+1 to Cur+Sol[i] do
            for L2:=L1+1 to Cur+Sol[i] do writeln(L1,' ',L2);
          inc(Cur,Sol[i]);
        end;
      for L1:=Cur+1 to n do writeln(1,' ',L1);
    end;
 Begin
      Init;
      Main;
 End.

And I got WA on Test 18!
How 郁闷 I am!!!(Who can Translate the Chinese to English...)
Please help me. Thanks.
ACed Now...
Posted by 198808xc 6 Jul 2005 08:47
I got AC...
So fast. I have a Stupid error!!!

Add a Line before the Last Line of  "Procedure Main"
After the Sentence "for L1:=Cur+1 to n do"
Insert a Sentence: "if L1<>1 then "

Thus, the Program can Got AC!!!