Help me in solving EXACTSAVINGS problem

My issue

hi this is my code for the problem EXACTSAVINGS
what is wrong with my logic and code
please explain
if possible please let me know why i cant use this method

My code

#include <bits/stdc++.h>
#define ll long long
#define pll pair<long long ,long long > 
using namespace std;

int main() {
    // your code goes here
    int t;
    cin>>t;
    while(t--){
        int n,x,z;
        cin>>n>>x>>z;
        //cout<<n<<x<<z<<endl;
        ll curr_sum = 0;
        bool flag = false;
        ll a=0;
        for(int i=1;i<=n;i++){
            cin>>a;
            if(flag) continue;
            if((curr_sum+z)%x==0){
                //cout<<"YES"<<curr_sum<<z<<x<<endl;
                cout<<(curr_sum+z)/x<<endl;
                flag = true;
            }
            curr_sum += a;
            
        }
        if(!flag) cout<<"-1"<<endl;
    }
    return 0;
}

Problem Link: Exact Savings Practice Coding Problem - CodeChef