My code is running correct if i use int data type but for long long , answer is always 1?

#include
using namespace std;
long long* pre_computing(int a[],int n)
{
long long* p=new long long[n];
p[0]=a[0];
for(int i=1;i<n;i++)
p[i]=a[i]+p[i-1];
return p;
}
int find_min(long long p[],int n,int k)
{
long long s,d,min=1000000;
int ans;
for(int i=0;i<n;i++)
{
s=i+k-1;
if(s<n)
{
d=p[i+k-1]-p[i-1];
if(min>d)
{
min=d;
ans=i;
}
}
}
return ans;
}
int main()
{
int n,k;
cin>>n>>k;
int* a=new int[n];
for(int i=0;i<n;i++)
cin>>a[i];
long long* p=pre_computing(a,n);
int ans=find_min(p,n,k);
cout<<a[ans];
delete []a;
delete []p;
return 0;
}

@namangarg31 hey could you provide your code in coding blocks IDE.
Thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.