Computing Olympiad Problem Doubt!

Hey, I was solving the same question using JAVA, but I got a WA in the second last test case of the first sub-task and the last test case of the second sub task. Rest all 13 test cases were AC. Can someone look at my code, I have literally been scratching my head for two hours.
Problem page: https://www.codechef.com/ZCOPRAC/problems/ZCO12001
Code submission and test result: https://www.codechef.com/viewsolution/12146831

import java.util.*;
class ZCO12001
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=sc.nextInt();
        }
        int c1=0;
        int c2=0;
        int s1=0;
        int s2=0;
        int h=0;
        int i=0;
        do
        {
            int c2x=0;
            int s2x=0;
            if(a[i]==1)
            {
               h++;
               i++;
               c2x=1;
               s2x=i;
               while(h>0)
               {
                   if(a[i]==1)
                   {
                       h++;
                       i++;
                    }
                    else
                    {
                        h--;
                        i++;
                    }
                   if(c1<h)
                    {
                        c1=h;
                        s1=i;
                    }
                   c2x++;
               }
            }
            else
            {
                i++;
            }
            if(c2x>c2)
            {
                c2=c2x;
                s2=s2x;
            }
        }while(i<n);
        System.out.println(c1+" "+s1+" "+c2+" "+s2);
    }
}