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 1028. Stars

Costel::icerapper@k.ro Why am I getting a wrong answer... here's my source [1] // Problem 1028. Stars 27 Feb 2002 13:11
program timus_1028;
const
  maxn=15000;
type
  tcoord=record x,y:integer end;

function Greater(c1,c2:tcoord):boolean;
begin
  Greater:=(c1.x+c1.y)>(c2.x+c2.y);
end;

type
  ta=array[1..maxn]of tcoord;
  tv=array[0..maxn]of word;
var
  n:integer;
  a:ta;
  v:tv;

procedure read_data;
var
  i:integer;
begin
  readln(n);
  for i:=1 to n do
    readln(a[i].x,a[i].y);
end;

procedure Switch(var a,b:tcoord);
var
  c:tcoord;
begin
  c:=a;
  a:=b;
  b:=c;
end;

procedure quicky(start,stop:integer);
var
 ini,fin:integer;
 step:integer;
begin
  if start>=stop then
    exit;
  ini:=start; fin:=stop; step:=1;
  while ini<fin do
  begin
    if Greater(a[ini],a[fin]) then
    begin
      Switch(a[ini],a[fin]);
      step:=1-step;
    end;
    inc(ini,step); dec(fin,1-step);
  end;
  quicky(start,ini-1);
  quicky(fin+1,stop);
end;

procedure sort_data;
begin
  quicky(1,n);
end;

procedure init_data;
begin
  fillchar(v,sizeof(v),0);
end;

procedure make_data;
var
  i:integer;
  k:integer;
begin
  v[0]:=1;k:=0;
  for i:=2 to n do
  begin
    if Greater(a[i],a[i-1]) then
      inc(k);
    inc(v[k]);
  end;
end;

procedure writ_data;
var
  i:integer;
begin
  for i:=0 to n-1 do
    writeln(v[i]);
end;

begin
  read_data;
  sort_data;
  init_data;
  make_data;
  writ_data;
end.
3
1 1
4 1
3 10

The Correct answer is :
1
2
0