ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1126. Магнитные бури

Please, give me a hint. My program gets Time Limit.
Послано Avanesov 23 мар 2002 15:48
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 (-)
Послано MadPsyentist/Sam 25 мар 2002 10:20
Re: use suitable data structure (-)
Послано Junjie Liang 25 мар 2002 16:45
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 (-)
Послано MadPsyentist/Sam 26 мар 2002 14:42
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