Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):

/*
author: Rahul
time: 2025-02-03 23:14 (GMT+5:30)
*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#define debugArray(arr, n) cerr << #arr <<" "; _print(arr, n); cerr << endl;
#else
#define debug(x)
#define debugArray(arr, n)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

template <class T, size_t N> void _print(array <T, N> &v) {
    cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";
}

template <class T> void _print(T arr[], int n) {
    cerr << "[ "; for (int i = 0; i < n; i++) {_print(arr[i]); cerr << " ";} cerr << "]";
}

void solve(){
    ll n;
    cin>>n;
    vector<ll>a(n);
    for (ll i=0; i<n;i++){
        cin>>a[i];
    }
    ll ans=LLONG_MIN;
    
    while(1){
        if(a.size()==1){
            ans= max(ans,a[0]);
        break;
    }
        ll sum=accumulate(a.begin(), a.end(),0);
        ll diff=0;
        vector<ll>a1;
        for(ll j=0; j<a.size();j++){
            if(j!=a.size()-1){
                diff+=a[j+1]-a[j];
                a1.pb(a[j+1]-a[j]);
            }

        }
        ans= max(diff,ans);
        ans=max(-1*diff,ans);
        ans=max(ans,sum);
        a=a1;
        debug(diff);
        debug(sum);
    }
    cout<<ans<<"\n";
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("Error.txt", "w", stderr);
#endif
    fastio();

    int t = 1;
    cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}


Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;

const int N = 100;

void get_sum(int n, long long *sum, long long *a) {
    *sum = 0;
    for (int i = 0; i < n; i++) *sum += a[i];
    *sum = abs(*sum);
}

void make_new(long long *a, int n) {
    long long b[n];
    copy(a, a + n, b);
    for (int i = 0; i < n - 1; i++) {
        a[i] = b[i + 1] - b[i];
    }
}

long long solve(int n, long long *a) {
    long long sum, ans;
    for (int i = 0; i < n; i++) ans += a[i];
    while (n > 1) {
        make_new(a, n);
        n--;
        get_sum(n, &sum, a);
        ans = max(ans, sum);
    }
    return ans;
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int tt, n;
    long long a[N];
    cin >> tt;
    while (tt--) {
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        cout << solve(n, a) << '\n';
    }
    return 0;
}