I did this by keeping i,j as 0 and incrementing it as per condition.

I was thinking whether this problem could also be approached by Dynamic programming.

Can anyone tell me?

Active In

Competitive Programming

Featured Contributions

reply in this discussion

n=int(raw_input())arr=list()forzinxrange(n):a,b=[int(i)foriinraw_input().split()]arr.append(min(a,b))arr.sort()t = 0foriinarr:ifi>t:t += 1

I solved it in about the same way Lakpa did.

He did the sorts and all in more compact way.

And I got TLE too in 0 8 and 9

is I/O Optimization worth it?

Read more… (35 words)

reply in this discussion

z=[int(i)foriininput().split()]n=z[0]k=z[1];a=z[2:2+n]b=z[2+n:len(z)]deff(a, b):a.sort()b.sort(reverse=True)i=j=0kk=kwhileTrue:ifb[j]<a[i]:breaka[i],b[j]=b[j],a[i]i+=1j+=1kk-=1ifkk==0:breakreturnmax(a)+max(b)ans = min(f(a[:], b[:]), f(b, a))

Only the 9th Test case is giving WA rest are all AC.

Please help. I cant seem to find out why. Ive pondered over this for hours. Looked for all possible solutions but nothing.

Please reply ASAP guys.

Read more… (38 words)

reply in this discussion

Read more… (18 words)

reply in this discussion

reply in this discussion