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 1079. Maximum

Why my program does not work?
Posted by Nikolai Sakharnykh 26 Jan 2002 22:06
I don't no why my program get Wrong Answer???
There is my program:

const maxn = 100000;
var n,i,max,st: longint;
    a: array [0..maxn] of longint;
begin
     read(n);
     fillchar(a,Sizeof(a),0);
     a[0]:=0; a[1]:=1; st:=0;
     while n <> 0 do begin
           for i:=st to n do begin
               a[2*i]:=a[i]; a[2*i+1]:=a[i]+a[i+1]; end;
           max:=1;
           for i:=0 to n do if a[i] > a[max] then max:=i;
           write(a[max]); if n > st then st:=n;
           read(n);
     end;
end.
That's easy!(+)
Posted by shitty.Mishka 26 Jan 2002 22:19
First, change write to writeln.
Then you'll get CRASH, because in a[2*i+1]:=.. i can be 100000, so,
you should have an array not [0..100000], but [0..200001].

Good luck!
Re: That's easy!(+)
Posted by Nikolai Sakharnykh 26 Jan 2002 22:24
Thank you!