Candies | hackerrank greedy alogrithms

here is my code, please someone tell what is wrong in this

#include<bits/stdc++.h>
using namespace std;
long long int limit;
long long int *memory;

long long int candle(int n,int a[])
{

if(n>=limit)
	return 1;
if(a[n+1]>a[n])	
{
	if(*(memory+n)>=*(memory+n+1))
                  {
		*(memory+n+1)=*(memory+n+1)+*(memory+n);
                  }
	else
		*(memory+n+1)+=1;
	     // //(*(memory+n)=);
	if(n<limit-2)
	           candle(n+1,a);
	
	return *(memory+n);
}
else
{	
	if(*(memory+n)>*(memory+n+1))
		candle(n+1,a);
		
	else if(n<limit-2)
		*(memory+n)=( *(memory+n) + candle(n+1,a));
	
	else
		*(memory+n)=(*(memory+n)+*(memory+n+1));
	
	return *(memory+n);
}

}
int main()
{
cin>>limit;
int arr[limit];
long long int mem[limit];

    for(int i=0;i<limit;i++)
      {
	cin>>arr[i];
	mem[i]=1;
      }
   memory=mem;
  candle(0,arr);
long long int tot=0;
 
    for(int i=0;i<limit;i++)
	tot+=mem[i];

printf("%lld",tot);

return 0;

}

Please Format your code.

can you understand code now