Find the sum - PAIRSUM2 - Sept Lunch Time

This is my code for PAIRSUM2

#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        int n,q;
        cin>>n>>q;
        unsigned long long b[n-1];
        unsigned long long int k;
        for(int i=0;i<n-1;i++){
            cin>>k;
            b[i]=k;
        }
        while(q--){
            int x,y;
            cin>>x>>y;
            if(abs(x-y)&1==1){
                int z = max(x,y);
                int z1 = min(x,y);
                unsigned int check = 1;
                long long ans = 0;
                for(int i=z1-1;i<z-1;i++){
                    if(check%2==0){
                        ans -= b[i];
                    }
                    else{
                        ans += b[i];
                    }
                    check++;
                }
                cout<<ans<<endl;
            }
            else{
                cout<<"UNKNOWN"<<endl;
            }
        }
    }
	return 0;
}

I am getting TLE for the second sub task ?

This the correct code:
We can get the list of numbers A[n] by considering first element as 0, A[0] = 0,
then using

A[i] = B[i-1] - A[i-1]

rest of the elements can be found:

  #include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        ll n,q;
        cin>>n>>q;
        ll b[n-1];
        ll k;
        for(int i=0;i<n-1;i++){
            cin>>k;
            b[i]=k;
        }
        ll a[n];
        a[0] = 0;
        for(int i=1;i<n;i++){
            a[i] = b[i-1] - a[i-1];
        }
        while(q--){
            int x,y;
            cin>>x>>y;
            if(abs(x-y)&1==1){
                cout<<a[x-1]+a[y-1]<<endl;
            }
            else{
                cout<<"UNKNOWN"<<endl;
            }
        }
    }
	return 0;
}