Skip to content

Commit d43724d

Browse files
authored
Maximum sum of increasing subsequence
if input is {1, 101, 2, 3, 100, 4, 5}, then output should be 106 (1 + 2 + 3 + 100), if the input array is {3, 4, 5, 10}, then output should be 22 (3 + 4 + 5 + 10) if the input array is {10, 5, 4, 3}, then output should be 10
1 parent 229f8d6 commit d43724d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: MaxSumOfIncreasinSubsequence

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ts=int(input())
2+
l3=[]
3+
l1=[]
4+
for j in range (ts):
5+
n=int(input())
6+
l3.clear()
7+
li=list(map(int, input().split()))
8+
for i in range(1,n):
9+
t=li[i-1]
10+
for j in range(0,i):
11+
if(li[i]>li[j]):
12+
t=t+li[j]
13+
l3.append(t)
14+
if(len(l3)!=0):
15+
print (max(l3))
16+
li.clear()

0 commit comments

Comments
 (0)