Game of two stack csharp

Code Example - Game of two stack csharp

                
                        public static int twoStacks(int maxSum, List<int> a, List<int> b)
{
    int i =0;
    int sum =0;
    while(a.Count>i && sum + a[i]<= maxSum)
    {
        sum+=a[i++];
    }
    var count = i;
    var j = 0;
    while(j<b.Count && i>=0)
    {  
        sum+=b[j++];
        while(sum > maxSum && i>0)
        {
            sum-=a[--i];
        }
        if(sum<=maxSum && i+j>count)
            count=i+j;
    }
    return count;
}