< Back to forum

my code is giving right output but in codechef it is giving wrong ans to the problem LINK TO QUESTN (SUMQ)... https://www.codechef.com/problems/SUMQ

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

#define module 1000000007

int main()
{
int t;
cin>>t;
while(t--)
{
int p,q,r,i,j,k;
cin>>p>>q>>r;
int a[p],b[q],c[r];

for(i=0;i<p;i++)
{
cin>>a[i];
}

for(i=0;i<q;i++)
{
cin>>b[i];
}

for(j=0;j<r;j++)
{
cin>>c[j];
}

sort(a,a+p);
sort(b,b+q);
sort(b,b+r);

int ans1[10000]={0};
int ans2[10000]={0};
j=0;
int z1=0,z2=0;

for(i=0;i<q;i++)
{
for(j=0;j<p;j++)
{
 
  if(b[i]>=a[j])
 {
  ans1[z1]=b[i]+a[j];
  ans1[z1]=ans1[z1]%module;
   z1++;
 }
 else
 {
     ans1[z1]=0;
      break;
    
 }
}


for(k=0;k<r;k++)
{
 if(b[i]>=c[k])
 {
     ans2[z2]=b[i]+c[k];
     ans2[z2]=ans2[z2]%module;
       z2++;
 }
 else
 {
     ans2[z2]=0;
     break;
 }

}
}

int s=0;

for(i=0;i<z1;i++)
{
  if(ans1[i]!=0)
  {
   for(j=0;j<z2;j++)
   {
    if(ans2[j]!=0)
       {
           s=s+((ans1[i]*ans2[j])%module);

       }

    }

   }
}

s=s%module;
cout<<s<<endl;

}
return 0;

}

 

Asked by: Manish_Kumar_Savita on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.


Enter your answer details below:


Enter your comment details below:




0 Answer(s)

Instruction to write good question
  1. 1. Write a title that summarizes the specific problem
  2. 2. Pretend you're talking to a busy colleague
  3. 3. Spelling, grammar and punctuation are important!

Bad: C# Math Confusion
Good: Why does using float instead of int give me different results when all of my inputs are integers?
Bad: [php] session doubt
Good: How can I redirect users to different pages based on session data in PHP?
Bad: android if else problems
Good: Why does str == "value" evaluate to false when str is set to "value"?

Refer to Stack Overflow guide on asking a good question.