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 1510. Order

PROBLEM WITH A PROBLEM
Posted by Alex TKTL 14 Mar 2007 18:28
Why this source got WA#13

var a:array[1..5000]of longint;
n,k,i,j,l,r,mid,com,cout:longint;
procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin i:=l; j:=r; x:=a[(l+r) DIV 2];
repeat
while a[i]<x do i:=i+1;
while x<a[j] do j:=j-1;
if i<=j then
begin y:=a[i]; a[i]:=a[j]; a[j]:=y;
i:=i+1; j:=j-1;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin read(n);
for i:=1 to n do
read(a[i]);
sort(1,n);
mid:=-maxlongint;
cout:=1; com:=0;
for i:=2 to n do
if a[i]=a[i-1] then inc(cout)
else if cout>mid then
begin mid:=cout;
cout:=1;
com:=a[i-1];
end;
if ((com=0)and(n>0)) then com:=a[1]
else
if (mid<cout) then com:=a[n]
else
if ((com=0)and(n=0)) then com:=0;

write(com);
end.

Edited by author 16.03.2007 10:55
Re: PROBLEM WITH A PROBLEM
Posted by Romko [Lviv NU] 14 Mar 2007 18:29
3 of course
No subject
Posted by Alex TKTL 15 Mar 2007 12:48


Edited by author 16.03.2007 10:54
Re: Why
Posted by Shady TKTL 15 Mar 2007 16:55


Edited by author 16.03.2007 10:56