Associated Course(s):
Must Do Interview Preparation

Given an array **A** of **N** positive integers. Find the **sum** of **maximum sum increasing subsequence** of the given array.

**Input:**

The first line of input contains an integer **T** denoting the number of test cases. The first line of each test case is N(the size of array). The second line of each test case contains array elements.

**Output:**

For each test case print the required answer in new line.

**Constraints:**

1 ≤ T ≤ 100

1 ≤ N ≤ 10^{6}

1 ≤ A_{i} ≤ 10^{6}

**Example:**

**Input:**

2

7

1 101 2 3 100 4 5

4

10 5 4 3

**Output:**

106

10

**Explanation:**

**Testcase 1:** All the increasing subsequences are : (1,101); (1,2,3,100); (1,2,3,4,5). Out of these (**1, 2, 3, 100**) has maximum sum,i.e., 106.

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.

VivSisMMM | 164 |

d_Coder00 | 163 |

ajayjadhav35 | 153 |

Astikeysingh | 148 |

Sathvik Avasarala | 143 |

Pulkit__Sharma__ | 658 |

Anirban166 | 565 |

abducodes | 542 |

Sathvik Avasarala | 506 |

Found_me | 494 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4559 |

Login to report an issue on this page.