#include
#include <stdio.h>
using namespace std;
int main() {
int t;
cin >> t;
for(int s=0;s<t;s++)
{
int n,temp=0,c=0;
cin >> n;
int a[n];
for(long long int i=0;i<n;i++)
{
cin >> a[i];
}
for(long long int i=0;i<n-2;i++)
{
c=a[i]+a[i+1]+a[i+2];
if(c>temp)
{
temp=c;
}
}
c=a[0]+a[n-2]+a[n-1];
if(c>temp)
{
temp=c;
}
c=a[0]+a[1]+a[n-1];
if(c>temp)
{
temp=c;
}
cout << temp;
cout << "\n";
}
// your code goes here
return 0;
}
can anyone explain me whats wrong in my code its showing wrong answer.
All the three coders should be friends of each other. The coder having skill 12 isn’t friends with the one having skill 10 as they are not 2 places to the left or right of himself.
1 Like
Please include a link to your submission as it would allow us to debug it much more easily.
Hi,
Just changing the datatype from int to long long gives AC.
Here is the link of the modified solution : CodeChef: Practical coding for everyone
Hope you have a great day.
Its circle right so last indexed and 1st indexed person can also be friends ,
So the answer should be 28 .
But my AC code is giving answer 18
In the problem statement they have not mentioned it should be consecutive .
I am confused
No ans should be 18 only as in a set of 3 coders “every” pair of coders should be friends , so just check if all possible pairs are friend or not
2 Likes