https://cses.fi/problemset/task/1661

i use the prefix sum for this task but it seem like the sum didn’t add the negative number , pls help me to fix it

#include <bits/stdc++.h>

#define ll long long

using namespace std;

ll a[10000000] ;

int main()

{

ll n,x;

cin>>n>>x;

for(int i=1;i<=n;i++) cin >> a[i] ;

ll sum = 0 , j=0;

ll ans = 0 ;

for(int i=1;i<=n;i++) {

sum+= a[i];

while (sum > x )

{

sum = abs(sum - a[j]);

j++;

}

if (sum == x) ans++;

}

cout << ans;

}