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

Why I have got Wrong Answer? Could someone give me some tests?
Posted by Koala 2 Mar 2003 17:01
{This is my program}
program p1169;

const
  maxn=100;
  maxd=maxn*(maxn-1) div 2;

var
  d,f:array [0..maxd] of longint;
  b:array [1..maxn] of longint;
  n,e,i,delta,j,k,p,tail,top:longint;

begin
  read(n,e);
  e:=(n*(n-1) div 2)-e;

  for i:=0 to maxd do d[i]:=maxlongint;
  fillchar(f,sizeof(f),0);
  d[0]:=0;
  for i:=3 to maxn do
  begin
    delta:=i*(i-1) div 2;
    for j:=maxd downto 0 do
      if d[j]<>maxlongint then
      begin
        k:=j+delta; p:=d[j]+i;
        while k<=maxd do
        begin
          if p<d[k] then
          begin
            d[k]:=p;
            f[k]:=i;
          end;
          k:=k+delta; p:=p+i;
        end;
      end;
  end;

  if d[e]>n then
  begin
    writeln(-1);
    exit;
  end;

  tail:=0;
  i:=e;
  while i>0 do
  begin
    inc(tail); b[tail]:=f[i];
    i:=i-(f[i]*(f[i]-1) div 2);
  end;

  top:=0;
  for i:=1 to tail do
  begin
    writeln(top+1,' ',top+b[i]);
    for j:=top+2 to top+b[i] do writeln(j-1,' ',j);
    top:=top+b[i];
  end;
  for i:=top+1 to n do
    if i<>1 then writeln(i,' ',1);
end.