DSA series contest-2 Chef in the queue

What is wrong with my code?
And also please if you can then please give some clarity on question ?

Here is a question link CodeChef: Practical coding for everyone

using namespace std;
#define ll long long int
int main() {

    ll n,k;
    cin>>n>>k;
    ll a[n];
    ll x[n];
    
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        x[i]=i;
        
    }
    ll ind,val;
    ind=n-1;
    val=a[n-1];
    for(ll i=n-2;i>=0;i--)
    {
        if(a[i]>val)
        {
            x[i]=ind;

        }
        else
        {
         if(a[i]<=val)
         {
             val=a[i];
             ind=i;
         }
        }
        
    }
    ll ans=1;
    
    for(ll i=0;i<n;i++)
    {
      //  cout<<x[i]<<" ";
        ans = ans*(x[i]-i+1);
        ans = ans % 1000000007;
    }
 //   cout<<endl;
    cout<<ans<<endl;
    
	return 0;
}

Think of the problem in this way: Whenever a junior chef is introduced all chefs senior to him will contribute to the fearfulness by passing their jobs to him & f=i2 - i1 + 1 will be multiplied to answer for every senior chef. You could use a DS like stack to optimize the solution.