Yes eventually you have to do that.
There are two bugs in your code. At first it looks all good to me. But after spending some hours on your code, I came to know about bugs. Guess what, fixing those two bugs gave me AC. So here it goes.
Looking this problem from DP point of view is quite interesting. I tried solving way Mohit has mentioned in his comment. But got WAs. I think I'm missing some clue while calculating backward segment.
Any help would be appreciated.
#!/usr/bin/python3def algo2():# inputsn = int(input())A = list(map(int, input().split()))B = list(map(int, input().split()))# Forward Segment i<=k segment finishing at indexDPF = [None]*nDPF = A # Base caseDPF = max(A, A+A)for k in range(2,n):DPF[k] = max(A[k], DPF[k-1]-A[k-1]+A[k]+B[k-1])#print(DPF)
Your code is correct. I think it's something to do with version of java they are using. That's why it's not getting AC. The version of python is also outdated. Whenever I had to submit problem on this site, I had to switch to older version. That's unfortunate.
I tried submitting your code on Codechef , it got AC. hurrah. So time to move on.
One suggestion since floor is an inbuilt function, better not to use it as a variable name. Though it is not giving any problem, still it would be good practice to do so.
A big blunder on problem statement. It says that you have to print next permutation lexicographically. Got some WAs on first attempt. I was debugging my code whole this time. But the moment I changed my output to integer order. It got accepted. So output should actually be integer order.
'45' < '5' in lexicographic order
45 > 5 in Integer order