Moony and ICPC team | CodeChef

#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.

https://www.codechef.com/viewsolution/30534353

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.

thank you so much.

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 :thinking::thinking::thinking::thinking:

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

Hmmm
Maybe you are right :sweat_smile::sweat_smile::sweat_smile: