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 1005. Stone Pile

And where is my mistake?
Posted by Radchenko Evgeniy 5 Jan 2010 15:50
program stone;
const nmax=20;
var
 i,k,n:byte;
 x:longint;
 a:array[1..nmax] of longint;
begin
read(n);
For i:=1 to n do read(a[i]);
 For i:=2 to n do
  For k:=n downto i do
   If a[k-1]>a[k] then
   begin
    x:=a[k];
    a[k]:=a[k-1];
    a[k-1]:=x;
   end;
 while n>1 do
 begin
   a[n-1]:=a[n]-a[n-1];
   dec(n);
  For i:=2 to n do
   For k:=n downto i do
    If a[k-1]>a[k] then
    begin
     x:=a[k];
     a[k]:=a[k-1];
     a[k-1]:=x;
    end;
 end;
write(a[1]);
read;
end.

May be I am too self-confident, but I am sure my program must work. But the fifth test refutes my confidence. If you are able to help, please,try to find mistake and write where it is=)
Re: And where is my mistake?
Posted by Sergey Lazarev (MSU Tashkent) 5 Jan 2010 22:11
Your algo is incorrect.

Test:
5
3 3 3 4 5

Answer: 0
Re: And where is my mistake?
Posted by Radchenko Evgeniy 6 Jan 2010 00:38
Thank you, I understood, I will at a new algo.