# Help me in solving POSITNEG problem

include
include
using namespace std;

int main() {

``````int z;
cin>>z;
for(int i=0;i<z;i++){

int n;
cin>>n;
int arr1[n];
int arr2[n];

for(int i=0;i<n;i++){
arr1[i]==pow(2,i);
cin>>arr2[i];
}

int arr3[n];
for(int i=0;i<n;i++){
arr3[i]==((arr1[i])*(arr2[i]));
}

int pos=0;
int nev=0;
int sum=0;
for(int i=0;i<n;i++){
for(int k=i;k<n;k++){
sum+=arr3[k];
if(sum>0){
pos++;
sum=0;
}
else if(sum<0){
nev++;
sum=0;

}

}
}

int k=abs(pos-nev);
cout<<k<<endl;

}

return 0;
``````

}

@shihrshsin
your logic is not right bro.
This is my code . With much simpler logic . Hope u will get it .

``````#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t--)
{
long long int n;
cin>>n;
long long int a[n];
long long int cnt_neg=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]<0)
cnt_neg+=(i+1);
}
long long int cnt_pos=(n*(n+1))/2  - cnt_neg;
cout<<abs(cnt_neg-cnt_pos)<<endl;
}
return 0;
}
``````

Let me know in case u get stuck at some point.