Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):

/*Don Paul*/
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define ld long double
#define el __int128
 
#define vl vector<ll>
#define ust unordered_set
#define ump unordered_map
#define prq priority_queue
 
#define pb push_back
#define pp pop_back
#define sz(x) ((int)x.size())
#define be(x) x.begin(), x.end()
#define farr(i, arr) for(int i=0; i<arr.size(); ++i)
#define fpr(it, m) for(auto it=m.begin(); it!=m.end(); ++it)


//Debugging tools

#define line cout<<"\n----------------------\n"
#define bline cout<<"\n======================\n"
#define parr(arr) for(int i=0; i<arr.size(); ++i) cout<<arr[i]<<" "; cout<<"\n";
#define pset(s) for(auto i=s.begin(); i!=s.end(); ++i) cout<<*i<<" "; cout<<"\n";
#define pmap(m) for(auto i=m.begin(); i!=m.end(); ++i) cout<<i->first<<" - "<<i->second<<"\n";
 
ll mod = 1e9 + 7;
ll inf = 7e18;
 
/*======================================================================================================================*/


ll find(vl &nums)
{
    ll i = 0;

    ll mx = -1e18;

    // parr(nums);

    while(sz(nums) != 1)
    {
        ll sum = 0;

        if(nums[0] < 0 && nums.back() < 0)
        {
            if(abs(nums.back()) > abs(nums[0]))
                reverse(be(nums));
        }

        else if(nums.back() < 0)
            reverse(be(nums));

        for(ll i=0; i<sz(nums)-1; ++i)
        {
            nums[i] = nums[i+1] - nums[i];
            // cout<<nums[i]<<" ";

            sum += nums[i];
        }

        nums.pop_back();

        // cout<<"\n";
        // cout<<sum<<"\n";

        mx = max(mx, sum);

        // line;
        ++i;
    }

    return nums[0];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);cerr.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
    #endif

    int ti;
    cin>>ti;

    ll x;

    while(ti--)
    {
        ll n;
        cin>>n;

        vl nums;
        vl tnums;
        ll sum = 0;

        for(ll i=0; i<n; ++i)
        {
            cin>>x;

            sum += x;
            nums.pb(x);
        }

        tnums = nums;
        ll ans = find(nums);
        ans = max(ans, sum);

        cout<<ans<<"\n";


        // line;


    }


    return 0;
}




















Submission (verdict: Wrong answer on test 2):

/*Don Paul*/
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define ld long double
#define el __int128
 
#define vl vector<ll>
#define ust unordered_set
#define ump unordered_map
#define prq priority_queue
 
#define pb push_back
#define pp pop_back
#define sz(x) ((int)x.size())
#define be(x) x.begin(), x.end()
#define farr(i, arr) for(int i=0; i<arr.size(); ++i)
#define fpr(it, m) for(auto it=m.begin(); it!=m.end(); ++it)


//Debugging tools

#define line cout<<"\n----------------------\n"
#define bline cout<<"\n======================\n"
#define parr(arr) for(int i=0; i<arr.size(); ++i) cout<<arr[i]<<" "; cout<<"\n";
#define pset(s) for(auto i=s.begin(); i!=s.end(); ++i) cout<<*i<<" "; cout<<"\n";
#define pmap(m) for(auto i=m.begin(); i!=m.end(); ++i) cout<<i->first<<" - "<<i->second<<"\n";
 
ll mod = 1e9 + 7;
ll inf = 7e18;
 
/*======================================================================================================================*/


ll find(vl &nums)
{
    ll i = 0;

    ll mx = -1e18;



    while(sz(nums) != 1)
    {
        ll sum = 0;

        if(nums[0]-nums.back() > nums.back()-nums[0])
            reverse(be(nums));

        for(ll i=0; i<sz(nums)-1; ++i)
        {
            nums[i] = nums[i+1] - nums[i];
            // cout<<nums[i]<<" ";

            sum += nums[i];
        }

        nums.pop_back();

        // cout<<"\n";
        // cout<<sum<<"\n";

        mx = max(mx, sum);

        // line;
        ++i;
    }

    return nums[0];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);cerr.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
    #endif

    int ti;
    cin>>ti;

    ll x;

    while(ti--)
    {
        ll n;
        cin>>n;

        vl nums;
        vl tnums;
        ll sum = 0;

        for(ll i=0; i<n; ++i)
        {
            cin>>x;

            sum += x;
            nums.pb(x);
        }

        tnums = nums;

        // parr(nums);
        // cout<<sum<<"\n";

        ll ans = find(nums);
        ans = max(ans, sum);

        cout<<ans<<"\n";


        // line;


    }


    return 0;
}