why is this code not working?

im trying to make a solution for this problem without using the modulo concept https://www.codechef.com/problems/CHRL4 but my output is always coming wrong. please help someone.

#include <bits/stdc++.h>

using namespace std;

int main()
{
int n, k, p, i, e, f, temp;
cin >> n >> k;
int a[100000];
for (i=0; i<n; i++)
cin >> a[i];

p=1;

for (i=0; i<=n; i++) {
while (1<=n-1 && n-1>=k) {        
p *=a[i];
i++;
n--;
}
}




f=p*n*1;
cout << f;

return 0;

}

You can Visit Editorial to CHRL4.

Its not a beginner level problem. Please try this after being acquainted with “Easy” section. It needs concepts on dynamic programming.

//