title: Using array declarations shows runtime error, but it works fine when using vector declaration. Why?
body: <p><strong>This is a solution for Max sum K-partitions problem, when I use array declarations it shows Runtime error, but works fine with vector declarations. Can't figure out why?
  How they are different?</strong></p>
  
  <p><strong>Max Sum K-partitions Problem Statement</strong>: Siraj has an array of N integers and an integer K. He wants to create a subsequence of this array with some conditions applied. He builds ceil(N/K) blocks of this array with size of each block as [i∗K+1,min((i+1)∗k,N)] for 0≤i≤N/K. For two consecutive integers in this subsequence, he wants the integers to be of two different blocks. (It is not a compulsion to have one integer from each block). Also, lets say the indexes of any two integers of this subsequence be i and j, then he wants |i−j| != K. Siraj takes the sum of integers in the subsequence. He wonders what can be the maximum sum obtained? Help siraj in this problem.</p>
  
  <pre><code>#include&lt;bits/stdc++.h&gt;
  using namespace std;
  
  typedef long long int ll;
  
  ll maxsum(ll arr[], ll n, ll k){
  
      ll dp[n]={0};   // vector&lt;ll&gt; dp(n,0);
      ll max1=INT_MIN;
      ll max2=INT_MIN;
      ll maxind=-1;
      ll i = 0;
      for(i = 0 ; i &lt; k ;i++){
          dp[i] = arr[i];
          if(arr[i] &gt; max1){
              max2 = max1;
              max1 = arr[i];
              maxind = i;
              continue;
          }
          max2 = max(max2 , arr[i]);
      }
  
  
      while(count--){
          pos = i;
          for( ; i &lt; min(n, pos+k) ; i++){
              dp[i] = arr[i];
              if(arr[i] &gt;= 0 ){
                  if(abs(i-maxind) != k){
                      dp[i] += max1;
                  }else
                  dp[i] += max2;
              }else
              dp[i] = max1;
          }
  
          for(i  = pos ; i &lt; min(n,pos+ k) ; i++){
              if(dp[i] &gt; max1){
                  max2 = max1;
                  max1 = dp[i];
                  maxind = i;
                  continue;
              }
              max2 = max(max2, dp[i]);
          }
      }    
      return max1;
  }
  int main(){
      ll n,k;
      cin&gt;&gt;n&gt;&gt;k;
      ll a[n];   //vector&lt;ll&gt; a(n);
      for(int i=0;i&lt;n;i++)
          cin&gt;&gt;a[i];
      cout&lt;&lt;maxsum(a,n,k)&lt;&lt;"\n";
  return 0;
  }
  
  </code></pre>