Please Login in order to post a comment
I have a solution for this problem. Check my code when solved.
i also think testcases are wrong
i m unable to spot the error in this code so plz help.........my code is-----#include
int main() { int i,t,n; long int a[1000],b[1000],m_sum1=0,m_sum2=0; long long int sum=0; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%ld",&a[i]); for(i=0;i<n;i++) scanf("%ld",&b[i]); for(i=0;i<n;i++) { if(a[i]>0) m_sum2 +=a[i]; else m_sum1+=a[i]; } if(m_sum2>(-1*m_sum1)) sum=m_sum2*m_sum2; else sum=m_sum1*m_sum1; m_sum1=0;m_sum2=0; for(i=0;i<n;i++) { if(b[i]>0) m_sum2 +=b[i]; else m_sum1+=b[i]; } if(m_sum2>(-1*m_sum1)) sum+=m_sum2*m_sum2; else sum+=m_sum1*m_sum1; printf("%lld",sum); } /* Enter your code here. Read input from STDIN. Print output to STDOUT */ return 0; }
Guys, the test cases are wrong here. For example on the second case, we have: 8 -1 2, 4 -1 -5
The correct answer must be: (8+2)^2 + (-1-5)^2 = 136, but test output is 101, which is totally wrong
Do check the editorial for a working approach.
The indices {i1,i2,...,ik} have to be the same for both A and B. The correct answer uses the indices {1,3} giving (8+2)^2 + (4-5)^2 resulting in 101.
No more comments
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
I have a solution for this problem. Check my code when solved.
i also think testcases are wrong
i m unable to spot the error in this code so plz help.........my code is-----#include
Guys, the test cases are wrong here. For example on the second case, we have: 8 -1 2, 4 -1 -5
The correct answer must be: (8+2)^2 + (-1-5)^2 = 136, but test output is 101, which is totally wrong
Do check the editorial for a working approach.
The indices {i1,i2,...,ik} have to be the same for both A and B. The correct answer uses the indices {1,3} giving (8+2)^2 + (4-5)^2 resulting in 101.
Do check the editorial for a working approach.