code runs absolutely fine in my ide.perfect output …codechef says its wrong …maybe constraints help…

using namespace std;

int main ()


int t,N;


for(int i=0;i<t;i++)


   int p=0; int n=0;


   int arr[N];








   for (int j=1;j<N;j++)




        int k=0;

     for(int m=0;m<j;m++)











         else p=p+arr[j];






return 0;


while asking any problem, format your code by ``` three backticks before and after code , and give the link of question.

sry here’s the link @ssrivastava990

cout<<s1<<" "<<s2<<endl;

and remove the first cout<<endl;

Learn language first , learn set in c++.

thnx it worked… i know all the simple basics of c++(class 11 nd 12) …i wanted to challenge myself so did the code using just that knowledge…so before doing ques on c++ what all topics should do? could u provide me with a list of some kind?

set , array , stack , queue , priority_queue , map , pair , vector in c++

1 Like

Bcz Test cases were weak , see what u did is taking an element and check whether it is present previously that means for each i u iterate a loop till i

so if u are at index n , u again iterate from 0 to n-1 , so overall complexity is O(N2) and here N is 106 => N2 = 1012 which is not possible to run in given Time Limit.

So better to take two set one for neg , one for pos and give the sum.

ohk…i couldnt understand some of the terms u used but got the gist of what u wanted to say…
so u are saying that first i should check that the particular term entered is positive or negative then check if that term has been entered before (sep for both cases) which will somehow decrease time taken?? (sry for using such crude terms…i wiill read about complexity nd time limits surely)…

Learn " set in c++ " then u will understand .

sure … u have been of gr8 help …despite being a 4 star u have helped nd answered my doubts nd trivial ques…thnx for the time and effort…have a nice day

1 Like