Can someone tell me why i am getting WA in this code

question link-(https://practice.geeksforgeeks.org/problems/stickler-theif/0)

#include<bits/stdc++.h>
using namespace std;

int main() {
//code
int t,n;
cin>>t;
while(t–)
{
cin>>n;
int a[n], i, temp[n+1]={0};
for(i=0;i<n;i++)
{
cin>>a[i];
}
if(n==1)
{
cout<<a[0];
}
else if(n==2)
{
cout<<max(a[0],a[1]);
}
else
{
temp[1]=a[0];
for(i=2;i<n+1;i++)
{
temp[i]=max(temp[i-1], temp[i-2]+a[i-1]);
}
cout<<temp[n]<<endl;
}
}
return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main() {
//code
int t,n;
cin>>t;
while(t–)
{
cin>>n;
int a[n], i, temp[n+1];
for(i=0;i<n;i++)
{
cin>>a[i];
}
if(n==1)
{
cout<<a[0]<<endl;
}
else if(n==2)
{
cout<<max(a[0],a[1])<<endl;
}
else
{
temp[1]=a[0];
temp[2] = max(a[0], a[1]);
for(i=3;i<n+1;i++)
{
temp[i]=max(temp[i-1], temp[i-2]+a[i-1]);
}
cout<<temp[n]<<endl;
}
}
return 0;
}

This is the corrected one you can crosscheck and get the errors

Some missing steps:
temp[0]=0; // if no houses…
temp[1]=1 // if one house …
temp[2]=max(a[0],a[1]); // if two houses
then start the loop from i=3.

dp Bottom up approach