The Maximum Sum Increasing Subsequence problem is to find the maximum sum subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the size array A representing the set of numbers

The second line of each test case contains N space separated integers denoting elements of the array A[ ].

**Output:**

Print all the elements of the maximum sum increasing subsequence for each test case in a new line.If there are more than one subsequence print the one with least number of elements.

**Constraints:**

1<= T <=100

1<= N <=1000

1<= A[ ] <=10000

**Example:**

**Input:**

7

1 101 2 3 100 4 5

**Output:**

1 2 3 100

Author: sujnesh

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

devsinghindra | 80 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 443 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.