https://www.codechef.com/LTIME70B/problems/POGOSTCK

why this program gives me SIGSEGV error ?

#include

#include

using namespace std;

int main()

{

int t,n,k,max,tempNum,tempIndex;

cin>>t;

while(t–)

{

cin>>n>>k;

int num[k];

```
for(int i=0;i<k;i++)
cin>>num[i];
for(int i=k;i<n;i++)
{
cin>>tempNum;
tempIndex=i%k;
if(num[tempIndex]<0)
num[tempIndex]=0;
num[tempIndex]+=tempNum;
}
max=*(max_element(num,num+k));
cout<<max<<endl;
}
```

}