Selection of maximum sub-array from the array
<p>Given an array of length <code>n</code>, it is required to find the maximum sum of elements one can choose if it is not allowed to choose more than two consecutive elements of the array. For example;</p>

<pre><code>n=5;
arr[5] = {10,3,5,7,3};
Output : 23
10+3+7+3=23
</code></pre>

<p>So I have written this code;</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
int max=0;
void solve(int arr[],int ind,int sum,int n,int count)
{
    if(ind==n){
          if(sum&gt;max)
              max=sum;
      }
      else{
          sum+=arr[ind];
          if(ind==n-1)
            solve(arr,ind+1,sum,n,1);
          if(ind==n-2 &amp;&amp; count&gt;1)
            solve(arr,ind+2,sum,n,1);
          if(ind&lt;n-1 &amp;&amp; count&lt;2){
              count++;
              solve(arr,ind+1,sum,n,count);
          }
          if(ind&lt;n-2)
              solve(arr,ind+2,sum,n,1);
          if(ind&lt;n-3)
              solve(arr,ind+3,sum,n,1);
      }
}
int main()
{
    int n;
    scanf("%d",&amp;n);
    int i=0,arr[n];
    while(i&lt;n){
        scanf("%d",&amp;arr[i]);
        i++;
    }
    int count=1;
    //going into all three possibilities
    solve(arr,0,0,n,count);
    solve(arr,1,0,n,count);
    solve(arr,2,0,n,count);
    printf("%d\n",max);
    return 0;
}
</code></pre>

<p>This program produces the expected outputs for <code>n&lt;1000</code> but shows runtime error (SIGSEGV) for larger inputs. What may be the reason?
More effective solutions are also welcome.....</p>