Sort by

recency

|

3 Discussions

|

  • [deleted]
    + 0 comments

    I have a solution for this problem. Check my code when solved.

  • + 0 comments

    i also think testcases are wrong

  • + 2 comments

    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;
    }
    
    • + 2 comments

      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

      • + 0 comments

        Do check the editorial for a working approach.

      • + 0 comments

        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.

    • + 0 comments

      Do check the editorial for a working approach.

No more comments