Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace __gnu_pbds;
using namespace std;
using namespace chrono;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// A.find_by_order(x), A.order_of_key(x)
#define int long long
#define pb push_back
#define pbb pop_back
#define float long double
#define mp make_pair
#define MOD 1000000007 // 998244353
#define INF 1e18
#define set_bits(x) __builtin_popcountll(x)
#define sp " "
#define endl "\n"
#define all(v) (v).begin(), (v).end()
#define PIE acos(-1)
#define F first
#define S second
#define rez(v, n) v.resize(n);
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = b; i >= a; i--)
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<vector<int>> vvi;

int ansg = INF;

int rec(vector<int> a, int revallowed){
    if(a.size()==1)
        return a[0];
    
    ansg = max(ansg,accumulate(all(a),0LL));
    int n=a.size();
    int ans = -INF;
    vector<int> b;
    for(int i=0;i<=n-2;i++){
        b.pb(a[i + 1] - a[i]);
    }

    ans=max(ans,rec(b,1));
    if(revallowed){
        reverse(all(a));
        ans=max(ans,rec(a,0));
    }
    return ans;
}

void solve()
{
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,0,n) cin>>a[i];
    ansg = -INF;
    cout<<max(ansg,rec(a,1))<<endl;



}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    auto start1 = high_resolution_clock::now();
    int t;
    t = 1;
     cin >> t;
    rep(testcase, 0, t) solve();
    auto stop1 = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop1 - start1);
    #ifndef ONLINE_JUDGE
        cerr << "Time: " << duration.count() / 1000 << " ms" << endl;
    #endif
}

Submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace __gnu_pbds;
using namespace std;
using namespace chrono;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// A.find_by_order(x), A.order_of_key(x)
#define int long long
#define pb push_back
#define pbb pop_back
#define float long double
#define mp make_pair
#define MOD 1000000007 // 998244353
#define INF 1e18
#define set_bits(x) __builtin_popcountll(x)
#define sp " "
#define endl "\n"
#define all(v) (v).begin(), (v).end()
#define PIE acos(-1)
#define F first
#define S second
#define rez(v, n) v.resize(n);
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = b; i >= a; i--)
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<vector<int>> vvi;

int ansg = INF;

int rec(vector<int> &a, int revallowed){
    if(a.size()==1)
        return a[0];
    
    ansg = max(ansg,accumulate(all(a),0LL));
    int n=a.size();
    int ans = -INF;
    vector<int> b;
    for(int i=0;i<=n-2;i++){
        b.pb(a[i + 1] - a[i]);
    }

    ans=max(ans,rec(b,1));
    if(revallowed){
        reverse(all(a));
        ans=max(ans,rec(a,0));
    }
    return ans;
}

void solve()
{
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,0,n) cin>>a[i];
    ansg = -INF;
    cout<<max(ansg,rec(a,1))<<endl;



}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    auto start1 = high_resolution_clock::now();
    int t;
    t = 1;
     cin >> t;
    rep(testcase, 0, t) solve();
    auto stop1 = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop1 - start1);
    #ifndef ONLINE_JUDGE
        cerr << "Time: " << duration.count() / 1000 << " ms" << endl;
    #endif
}