Skip to content

Commit

Permalink
Maximum Score # Problem 3
Browse files Browse the repository at this point in the history
  • Loading branch information
harrypotter0 committed Jan 20, 2018
1 parent fbf050f commit 2024e14
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
29 changes: 29 additions & 0 deletions CP/January Challenge 2018/kconcat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'''
listB.sort(reverse=True) # listB gets modified
listC = sorted(listB, reverse=True) # listB remains untouched
'''


for _ in range(int(input())):
n = int(input())
b = []
for __ in range(n):
a = map(int,raw_input().split())
b.append(sorted(a))
su = b[n-1][-1]
k1=su

for x in range(n-2,-1,-1):
flag = 0
for y in range(n-1,-1,-1):
if(b[x][y]<k1):
k1=b[x][y]
su+=k1
flag = 1
break
if(flag == 0):
break
if(flag == 0):
print("-1")
else :
print(su)
29 changes: 28 additions & 1 deletion CP/January Challenge 2018/maxscore.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
'''
listB.sort(reverse=True) # listB gets modified
listC = sorted(listB, reverse=True) # listB remains untouched
'''


for _ in range(int(input())):

n = int(input())
b = []
for __ in range(n):
a = map(int,raw_input().split())
b.append(sorted(a))
su = b[n-1][-1]
k1=su

for x in range(n-2,-1,-1):
flag = 0
for y in range(n-1,-1,-1):
if(b[x][y]<k1):
k1=b[x][y]
su+=k1
flag = 1
break
if(flag == 0):
break
if(flag == 0):
print("-1")
else :
print(su)

0 comments on commit 2024e14

Please sign in to comment.