Help me in solving TEMPBAL problem

My issue

what wrong i am doing can anyone tell pls

My code

#include <bits/stdc++.h>

using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector < int > a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int temp = 0;
        for (int i = 0; i < n - 1; i++) {
            if (a[i] > 0) {
                temp += a[i];
            }
            else {
                temp += -a[i];
            }
            if (a[i + 1] > a[i]) {
                a[i + 1] -= a[i];
            }
            else if(a[i+1]<a[i]){
                a[i + 1] += a[i];
            }
        }
        cout << temp << endl;
    }
    return 0;
}

Problem Link: Temperature Balance Practice Coding Problem