Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project1;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- const
- MAXIN = 100000;
- var
- n, i, j, max, maxi, top, x: integer;
- a, dp, p, time: array [0..MAXIN] of integer;
- s: string;
- procedure find(s: string; var n: integer);
- var
- i, top: integer;
- s1: string;
- begin
- top := 0;
- s := s+ ' ';
- s1 := '';
- for i := 1 to length(s) do
- if (s[i] = ' ') then
- begin
- inc(top);
- a[top] := strtoint(s1);
- s1 := '';
- end
- else
- s1 := s1 + s[i];
- n := top;
- end;
- begin
- readln(s);
- find(s, n);
- dp[0] := 1;
- for i := 1 to n do
- begin
- dp[i] := 1;
- for j := 1 to i - 1 do
- begin
- if (a[i] < a[j]) then
- if (dp[i] < dp[j] + 1) then
- begin
- p[i] := j;
- dp[i] := dp[j] + 1;
- end;
- end;
- end;
- max := 0;
- maxi := 0;
- for i := 1 to n do
- if (dp[i] > max) then
- begin
- max := dp[i];
- maxi := i;
- end;
- i := maxi;
- top := 0;
- while (i <> 0) do
- begin
- inc(top);
- time[top] := a[i];
- i := p[i];
- end;
- for i := top downto 1 do
- if (i = 1) then
- writeln(time[i])
- else
- write(time[i], ' ');
- readln;
- readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment