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;
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]);
if (sum == x) ans++;

cout << ans;


first of all the for loop you used for input of arrays in starting from 1
while arrays start from 0th index
and in while loop why there is sum-a[j] where all you have to do is to find sum
and the approach for the answers is taking multiple subarrays and checking the sum
for example in the test case there is 2 -1 3 5 -2
the possible sub-arrays for the sum x=7 is
this is first
and the second one is
this is the second
i think how it should be approached to be solved