< Back to forum

my code is giving right output but in codechef it is not passing all the inputs to the problem ..LINK TO QUESTN (ZCO12001)... https://www.codechef.com/ZCOPRAC/problems/ZCO12001

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

int main()
{
long long int n,i,p=0,pos=0,c,j,k,len;
cin>>n;

long long int a[n];

for(i=0;i<n;i++)
    cin>>a[i];

c=0;
k=0;

for(i=0;i<n;i++)
{

 if((a[i]==1))
 {
  c=1; //nestng depth
  k=i;  //postn

 for(j=i+1;j<n;j++)
 {
  k++;

  if(a[j]==1)
        c++;

  else
    break;

 }


 if(c>p)
    {
        p=c;
        pos=k;
    }

 }



}

cout<<p<<" "<<pos<<" ";



k=0;
p=0;
c=0;

for(i=0;i<n;i++)
{

 if((a[i]==1))
 {
  c=1;

  len=1;

 for(j=i+1;j<n;j++)
 {

  if(a[j]==1)
        {
            c++;
            len++;
        }
  else

        {
            c--;
            len++;
        }


  if(c==0)
      break;

 }


 if(len>p)

   {
       p=len;
       k=i+1;
   }


 }

}

cout<<p<<" "<<k;


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.