Question-:Problem - A - Codeforces
Code-:Submission #125755023 - Codeforces
Anyone?
try this
for(int i=0;i<v1.size();i++)
{
flag=1,flag1=1,flag2=1,flag3=1;
for(int j=0;j<v1.size();j++)
{
//this different line from your code
if(i!=j){
if(v1[i]<v1[j]&&v2[i]==v2[j])
flag=0;
else if(v1[i]>v1[j]&&v2[i]==v2[j])
flag1=0;
else if(v1[i]==v1[j]&&v2[i]<v2[j])
flag2=0;
else if(v1[i]==v1[j]&&v2[i]>v2[j])
flag3=0;
}
}
if(flag==0&&flag1==0&&flag2==0&&flag3==0)
count++;
}
instead of
for(int i=0;i<v1.size();i++)
{
flag=1,flag1=1,flag2=1,flag3=1;
for(int j=0;j<v1.size();j++)
{ //your doing mistake at this line increase j if
// i==j ,what happens at this line to understand
//like in condition you used if and else if
//i==0 && j==0 then j+=1 which is j==1 means you
// skip the condition at j==0 as well j==1
// every times so i think this the reason
if(i==j)
j+=1//here j incrase and next j is skiped
else if(v1[i]<v1[j]&&v2[i]==v2[j]) // because first condition is satisfied and another one is skiped and your code not checked **next j value**
flag=0;
else if(v1[i]>v1[j]&&v2[i]==v2[j])
flag1=0;
else if(v1[i]==v1[j]&&v2[i]<v2[j])
flag2=0;
else if(v1[i]==v1[j]&&v2[i]>v2[j])
flag3=0;
}
if(flag==0&&flag1==0&&flag2==0&&flag3==0)
count++;
}
1 Like
Thank you so much