Problem: 2050B - Transfusion
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>

using namespace std;

#define int long long int

const int N = 2 * 100010;

#define M 1000000007



void print_vect(vector<int> &v) {

    for (auto i : v) {

        cout << i << " ";

    }

    cout << endl;

}



vector<int> seg;



void build_seg(int ind, int low, int high, vector<int> &a) {

    if (low == high) {

        seg[ind] = a[low];

        return;

    }

    int mid = (low + high) / 2;

    build_seg(2 * ind + 1, low, mid, a);

    build_seg(2 * ind + 2, mid + 1, high, a);

    seg[ind] = __gcd(seg[2 * ind + 1], seg[2 * ind + 2]);

}



int seg_queries(int ind, int low, int high, int l, int r) {

    if (low >= l && high <= r)

        return seg[ind];

    if (high < l || low > r)

        return 0;

    int mid = (low + high) / 2;

    int left = seg_queries(2 * ind + 1, low, mid, l, r);

    int right = seg_queries(2 * ind + 2, mid + 1, high, l, r);

    return __gcd(left, right);

}



void point_update(int ind, int low, int high, int node, int val) {

    if (low == high && low == node) {

        seg[ind] = val;

        return;

    }

    int mid = (low + high) / 2;

    if (node <= mid && node >= low) {

        point_update(2 * ind + 1, low, mid, node, val);

    } else {

        point_update(2 * ind + 2, mid + 1, high, node, val);

    }

    seg[ind] = min(seg[2 * ind + 1], seg[2 * ind + 2]);

}



int binexp(int a, int b, int m) {

    int ans = 1;

    while (b) {

        if (b & 1) {

            ans *= a;

            ans = ans % m;

        }

        a = a * a;

        a = a % m;

        b = b / 2;

    }

    return ans % m;

}



int mod_inverse(int a, int b) {

    return binexp(a, b - 2, b);

}



int sol(int a, int b, int c) {

    int gcd = __gcd(a, b);

    int k1 = a / gcd;

    int k2 = b / gcd;

    return (mod_inverse(k1, k2) * (c / gcd)) % k2;

}



void dfs(vector<vector<int>> &graph, int node, vector<int> &par, vector<int> &vis) {

    if (vis[node] == 1) {

        return;

    }

    vis[node] = 1;

    for (auto child : graph[node]) {

        if (vis[child] == 1) {

            continue;

        }

        par[child] = node;

        dfs(graph, child, par, vis);

    }

}



int32_t main() {

    int t;

    cin >> t;

    while (t--) {

        int n;

        cin>>n;

        vector<int>v;

        int sum = 0;

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

            int x;

            cin>>x;

            v.push_back(x);

            sum += x;

        }

        if(sum%n!= 0 ){

            cout<<"NO"<<endl;

        }

        else{

            int k = sum/n;

            int fl = 0;

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

                int l = abs(v[i-1] - k);

                

                if(v[i-1]>=k){

                    v[i+1] += l;

                }

                else{

                    v[i+1]-=l;

                    if(v[i+1]<0){

                        fl = 1;

                        break;

                    }

                }

                v[i-1] = k;

            }

            //print_vect(v);

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

                if(v[i]!=k){

                    fl = 1;

                }

            }

            if(fl == 0){

                cout<<"YES"<<endl;

            }

            else{

                cout<<"NO"<<endl;

            }

            

        }

    }

}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;

#define int long long int

const int N = 2 * 100010;

#define M 1000000007



void print_vect(vector<int> &v) {

    for (auto i : v) {

        cout << i << " ";

    }

    cout << endl;

}



vector<int> seg;



void build_seg(int ind, int low, int high, vector<int> &a) {

    if (low == high) {

        seg[ind] = a[low];

        return;

    }

    int mid = (low + high) / 2;

    build_seg(2 * ind + 1, low, mid, a);

    build_seg(2 * ind + 2, mid + 1, high, a);

    seg[ind] = __gcd(seg[2 * ind + 1], seg[2 * ind + 2]);

}



int seg_queries(int ind, int low, int high, int l, int r) {

    if (low >= l && high <= r)

        return seg[ind];

    if (high < l || low > r)

        return 0;

    int mid = (low + high) / 2;

    int left = seg_queries(2 * ind + 1, low, mid, l, r);

    int right = seg_queries(2 * ind + 2, mid + 1, high, l, r);

    return __gcd(left, right);

}



void point_update(int ind, int low, int high, int node, int val) {

    if (low == high && low == node) {

        seg[ind] = val;

        return;

    }

    int mid = (low + high) / 2;

    if (node <= mid && node >= low) {

        point_update(2 * ind + 1, low, mid, node, val);

    } else {

        point_update(2 * ind + 2, mid + 1, high, node, val);

    }

    seg[ind] = min(seg[2 * ind + 1], seg[2 * ind + 2]);

}



int binexp(int a, int b, int m) {

    int ans = 1;

    while (b) {

        if (b & 1) {

            ans *= a;

            ans = ans % m;

        }

        a = a * a;

        a = a % m;

        b = b / 2;

    }

    return ans % m;

}



int mod_inverse(int a, int b) {

    return binexp(a, b - 2, b);

}



int sol(int a, int b, int c) {

    int gcd = __gcd(a, b);

    int k1 = a / gcd;

    int k2 = b / gcd;

    return (mod_inverse(k1, k2) * (c / gcd)) % k2;

}



void dfs(vector<vector<int>> &graph, int node, vector<int> &par, vector<int> &vis) {

    if (vis[node] == 1) {

        return;

    }

    vis[node] = 1;

    for (auto child : graph[node]) {

        if (vis[child] == 1) {

            continue;

        }

        par[child] = node;

        dfs(graph, child, par, vis);

    }

}



int32_t main() {

    int t;

    cin >> t;

    while (t--) {

        int n;

        cin>>n;

        vector<int>v;

        int sum = 0;

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

            int x;

            cin>>x;

            v.push_back(x);

            sum += x;

        }

        if(sum%n!= 0 ){

            cout<<"NO"<<endl;

        }

        else{

            int k = sum/n;

            int fl = 0;

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

                int l = abs(v[i-1] - k);

                

                if(v[i-1]>=k){

                    v[i+1] += l;

                }

                else{

                    v[i+1]-=l;

                    

                }

                v[i-1] = k;

            }

            //print_vect(v);

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

                if(v[i]!=k){

                    fl = 1;

                }

            }

            if(fl == 0){

                cout<<"YES"<<endl;

            }

            else{

                cout<<"NO"<<endl;

            }

            

        }

    }

}