fork download
  1. uses math;
  2. const
  3. fi='';
  4. fo='';
  5. maxn=trunc(1e6)+3;
  6. var
  7. st : array[1..maxn] of longint;
  8. a,l,r : array[1..maxn] of longint;
  9. i,j,n : longint;
  10. res : int64;
  11. top : longint;
  12. procedure enter;
  13. begin
  14. assign(input,fi);reset(input);
  15. readln(n);
  16. for i:=1 to n do read(a[i]);
  17. end;
  18. procedure push(x : longint);
  19. begin
  20. inc(top);
  21. st[top] := x;
  22. end;
  23. function get: longint;
  24. begin
  25. get := st[top];
  26. end;
  27. procedure process;
  28. begin
  29. top :=0 ;
  30. for i:=1 to n do
  31. begin
  32. while (top<>0) and (a[get]>=a[i]) do dec(top);
  33. if top=0 then l[i] := 0 else l[i] := get;
  34. push(i);
  35. end;
  36. top := 0;
  37. for i:=n downto 1 do
  38. begin
  39. while (top<>0) and (a[get]>=a[i]) do dec(top);
  40. if top=0 then r[i]:=n+1 else r[i] := get;
  41. push(i);
  42. end;
  43. for i:=1 to n do
  44. if r[i]-l[i]-1>=a[i] then
  45. res := max(res, a[i]);
  46. end;
  47. procedure print;
  48. begin
  49. assign(output,fo);rewrite(output);
  50. writeln(res);
  51. end;
  52. begin
  53. enter;
  54. process;
  55. print;
  56. end.
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.pas:1: warning: missing program header
prog.pas:1: error: module/unit interface `math' could not be imported
stdout
Standard output is empty