fork download
  1. program mountain;
  2.  
  3. const
  4. MAXN = 100000;
  5.  
  6. var
  7. ANS, N, i, j, lung : LongInt;
  8. P : Array of LongInt;
  9.  
  10. begin
  11.  
  12. (* assign(input, 'input.txt'); reset(input);
  13.   assign(output, 'output.txt'); rewrite(output);*)
  14.  
  15. ReadLn(N);
  16. SetLength(P,N);
  17. for i:=0 to N-1 do
  18. Read(P[i]);
  19. ReadLn();
  20.  
  21. ANS := 0;
  22.  
  23. i:=1;
  24. lung:=N;
  25. while i<lung-1 do
  26. begin
  27. if (P[i]<P[i-1]) and (P[i]<P[i+1]) then
  28. begin
  29. ANS:=ANS+1;
  30. for j:=i to lung-2 do begin P[j]:=P[j+1]; write(P[j],' '); end;
  31. writeln;
  32. lung:=lung-1;
  33. SetLength(P,lung);
  34. i:=i-1;
  35. end
  36. else i:=i+1;
  37. end;
  38. WriteLn(ANS);
  39. end.
Success #stdin #stdout 0s 5324KB
stdin
7
1 4 0 3 2 6 5
stdout
3 2 6 5 
6 5 
6 5 
3