|
|
back to boardPlease, give me a hint. My program gets Time Limit. program p1126; var a : array[1..14000] of integer; i, m : integer; x : integer; max: integer; function findmax : integer; var k : integer; res : integer; begin res:=0; for k:=1 to m do if res<a[k] then res:=a[k]; findmax:=res; end; begin readln(m); read(x); max:=0; i:=1; while (x<>-1) and (i<=m) do begin if max< x then max:=x; a[i]:=x; inc(i); read(x); end; Writeln(max); i:=1; while x<>-1 do begin if a[i]= max then begin a[i]:=x; max:=findmax; end else begin a[i]:=x; if a[i]>max then max:=a[i]; end; Writeln(max); i:=i mod m +1 ; read(x); end; end. use suitable data structure (-) Re: use suitable data structure (-) The first time I read this problem, I thought of using a heap. However, I could not implement it properly. How do you know which number to delete off the heap each time? I only know how to delete the max/min number (depending on min/max heap). Any hints/tips/help/aids will be appreciated. :) Re: use suitable data structure (-) look at the sample input 3 10 11 10 0 , delete 10 becase it's not in the period to consider anymore 0 , delete 11 0 , delete 10 1 , delete 0 so on... that is ,if you use heap (like me) , your heap must be able to delete not only the optimal data in the constrain of this problem (i don't know if it's bigger) , you can do the deletion in O(lg N) if still have no idea, feel free to mail to piyawut@se-ed.net |
|
|