you have to calculate the adjacent 3 elements sum…the sum 1st element with last two elements and similarly sum last element with 1st two elements…and every time you have to check the maximum sum of these three adjacent elements…
for _ in range(int(input())):
n=int(input())
ans=0
seq=map(int,input().split())
seq=list(seq)
if(n<6):
for j in range(3):
ans+=max(seq)
seq.remove(max(seq))
else:
for i in range(n):
thisans=seq[i]+seq[(i+1)%n]+seq[i-1]
ans=max(ans,thisans)
print(ans)
I think this is correct, but I don’t know python properly, just try putting each person in the middle, and take the max on both sides.
A[10,40,30,30,20] for this
1-> max((10+40+30),(10+20+30))–80
2-> max((40+30+30),(40+20+10))–100
3-> max((30+30+20),(30+40+10))–80
4-> max((30+30+40),(30+20+10))–100
5-> max((20+30+30),(20+10+40))–80
At last max(80,100,80,100,80)----100
So, there should be a sequence like this?:
thisans=seq[i]+max(seq[i+1],seq[i+2])+max(seq[i-1],seq[i-2])
I think in the question i didn’t get this. Thank you so much!
No I’m wrong
Corrected my code got AC
output is large so use long long int in C
Ans will be = seq[i] + max((seq[i+1] + seq[i+2]) ,(seq[i-1] + seq[i-2]))
and also for the 1st and last element cause the standing was circular
wlcm 
You can only take adjacent because the people on the edges also need to be friends, That wasn’t very clear in the question.
Yes…but they also mentioned that the array was circular
Yes, adjacent in the circle, read my new corrected code.
I think its Ok…cause i’m not used to with python…don’t know soo much…


Wow! Then I didn’t heard of python! Is python a programming language?
lol

I have a doubt after considering your approach.
The problem statement mentions that a team is formed out of three CP who are friends.
But it is also mentioned in the statement that a person is friend with 4 members, 2 of whom are in the right and 2 in the left.
Eg : [A,B,C,D,E,F,G,H]
Here, C is friend with {A,B,D,E}.But, can we say that they all are friends with each other? Absolutely NO!
**Hence selecting **
[quote=“cubefreak777, post:2, topic:56895”]
three of its elements such that one is selected out of 2 elements to the left and one out of the 2 elements standing to the right of current element of analysis
[/quote] will be a wrong approach, because, E is not a friend of {A,B}.
Please correct me if i’m wrong.