import java.util.Arrays;
import javax.swing.plaf.basic.BasicScrollPaneUI.VSBChangeListener;
public class NajdlhsiaVybranaRastucaPodpostupnost {
/**
* @param args
*/
public static int[] vsetko(int[] p) {
int[] d = new int[p.length];
for (int i = 0; i < p.length; i++) {
d[i] = 1;
for (int j = 0; j < i; j++)
if (p[j] < p[i])
d[i] = Math.max(d[i], d[j] + 1);
}
int najdlhsia = 0;
for (int i = 0; i < d.length; i++)
najdlhsia = Math.max(najdlhsia, d[i]);
int[] hotovo=new int[najdlhsia];
for(int i=p.length-1; i>=0; i--){
if(d[i]==najdlhsia){
hotovo[najdlhsia-1]=p[i];
najdlhsia=najdlhsia-1;
}
}
return hotovo;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] p={5,3,1,4,6,2,8,7};
System.out.println(Arrays.toString(vsetko(p)));
}
}