ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 2e9;
int a[N];
void solve() {
	int n, l, r;
	scanf("%d%d%d", &n, &l, &r);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	ll suml = 0, sumr = 0;
	priority_queue <int, vector<int>, greater<int> > ql, qr;
	for(int i = 1; i <= r; i++) {
		ql.push(a[i]);
	}
	for(int i = l; i <= r; i++) {
		suml += ql.top();
		ql.pop();
	}
	for(int i = l; i <= n; i++) {
		qr.push(a[i]);
	}
	for(int i = l; i <= r; i++) {
		sumr += qr.top();
		qr.pop();
	}
	printf("%lld\n", min(suml, sumr));
}
int main() {
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);
    int T = 1;
	scanf("%d", &T);
	while(T--) solve();

    return 0;
}

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

#define int 			long long int
#define double			long double
#define F			first
#define S 			second
#define pb 			push_back
#define all(x) 			x.begin(), x.end()
#define vi 			vector<int>
#define pii			pair<int, int>
#define rep(i, a, b) 		for(int i = a; i < b; i++)
#define CODE_START 		ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);

void solve() {
	int n, l, r;
	cin >> n >> l >> r;
	vi a(n);
	rep(i, 0, n) cin >> a[i];
	vi b;
	rep(i, l-1, r) b.pb(a[i]);
	sort(b.rbegin(), b.rend());
	int d = r-l+1;
	vi prefix(d+1);
	rep(i, 0, d) prefix[i+1] = prefix[i] + b[i];
	
	vi c;
	rep(i, 0, l-1) c.pb(a[i]);
	sort(all(c));

	int sum = 0, mn = prefix[d], len = 0;
	rep(i, 0, (int)c.size()) {
		if(sum + c[i] < prefix[i+1]) {
			sum += c[i];
			mn = min(mn, prefix[d] - prefix[i+1] + sum);
		}
		else break;
		len++;
		if(len == d) break;
	}

	vi e;
	for(int i = n-1; i >= r; i--) e.pb(a[i]);
	sort(all(e));

	sum = 0;
	len = 0;
	rep(i, 0, (int)e.size()) {
		if(sum + e[i] < prefix[i+1]) {
			sum += e[i];
			mn = min(mn, prefix[d] - prefix[i+1] + sum);
		}
		else break;
		len++;
		if(len == d) break;
	}

	cout << mn << "\n";
}

int32_t main() {
	#ifdef CODE_START
		CODE_START;
	#endif

	int t;	
	cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):

#include <bits/stdc++.h>

using namespace std;


//debugging
 
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x,y) cout << #x << ": " << x <<  " " <<#y << ": " << y << endl
#define deb3(x,y,z) cout << #x << ": " << x <<  " " <<#y << ": " << y <<  " " <<#z << ": " << z << endl

#define ll int64_t

void onlineJudge();


void solve(){
	long long a[2000];
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int now = n;
	long long ans = -1e18;
	for (int i = 1; i <= n; i++){
		long long sum = 0;
		for (int i = 1; i <= now; i++) sum = (sum + a[i]) ;
		if (i == 1) ans = max(ans, sum);
		else ans = max(ans, max(sum, ( - sum) ));
		for (int i = 1; i < now; i++) a[i] = (a[i + 1] - a[i]) ;
		now--;
	}
	cout << ans << endl; 


}

int main()
{
	onlineJudge();
	int t = 1;
    cin >> t;
	while(t--){
		solve();
	}

	return 0;
}


void onlineJudge(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	#if !defined(ONLINE_JUDGE) && !defined(codeblocks)
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
 
	#if defined(codeblocks) && !defined(ONLINE_JUDGE)
		freopen("input.txt", "r", stdin);
	#endif
 
}



Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 50

int t, n;
ll ans;
ll a[MAXN][MAXN];

int main(){
    cin >> t;
    while(t--){
        cin >> n;
        ans = 0;
        for(int i=0; i<n; i++){
            cin >> a[0][i];
            ans += a[0][i];
        }
        for(int j=1; j<n; j++){
            ans = max(ans,abs(a[j-1][0]-a[j-1][n-j]));
            for(int k=0; k<n-j; k++){
                a[j][k] = a[j-1][k+1] - a[j-1][k];
            }
        }
        if(n==1) cout << a[0][0]<< endl;
        else cout << ans << endl;
    }
    
    return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

// Function to compute the Greatest Common Divisor (GCD)
ll gcd(ll x, ll y) {
    return y == 0 ? x : gcd(y, x % y);
}

// Function to compute the Least Common Multiple (LCM)
ll lcm(ll x, ll y) {
    return (x / gcd(x, y)) * y;
}
vector<int>gra[100];
void solve(int n,int m)
{
    vector<int>v(n+1,0);
    for(int i = 0;i<m;i++)
    {
        int x,y;
        cin>> x >> y;
        v[x]++,v[y]++;
    }
    int cen = 0, cnted=0;
    for(int i = 1;i<=n;i++)
    {
        if(v[i]==1)cnted++;
        else if(v[i]==m)cen++;
    }
    if(cen==1&&cnted==n-1)
    {
        cout << "star topology";
        return ;
    }
    bool bus = (m==n-1);
    int one = 0;
    int two = 0;
    for(int i= 1;i<=n;i++)
    {
        if(v[i]==1)one++;
        else if(v[i]==2)two++;
        else
        {
            bus = false;
            break;
        }
    }
    if(one==2&& two==n-2&& bus)
    {
        cout << "bus topology";
        return ;
    }
    bool ring = (n==m);
    for(int i = 1;i<=n;i++)
    {
        if(v[i]!=2)
        {
            ring = false;
            break;

        }

    }
    if(ring)
    {
        cout << "ring topology ";
        return ;
    }
    cout << "unknown topology ";

}

int main() {

    int t;
    cin >>  t;
    while(t--)
    {
        int n,l,r;
        cin>> n >> l >> r;
        vector<int>a(n);
        for(int &i:a)cin>>i;
        l--;
        vector<int>temp(a.begin(),a.begin()+r);
        sort(temp.begin(),temp.end());
        vector<int>z(a.begin()+l,a.end());
        sort(z.begin(),z.end());
        ll sum1 = accumulate(temp.begin(),temp.begin()+r-l,0LL);
        ll sum2 = accumulate(z.begin(),z.begin()+r-l,0LL);
        cout << min(sum1,sum2)<< endl;

    }



    return 0;
}


Solution 2 (runtime: 109 ms):
#include <iostream>
#include <queue>
using namespace std;

typedef long long ll;

// priority_queue<int, vector<int>, greater<int> > q;
priority_queue<ll> q1;
priority_queue<ll> q2;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int testcases;
    cin >> testcases;
    while (testcases--) {
      ll n, l, r;
      cin >> n >> l >> r;

      for (ll i = 0; i < n; i++) {
        ll tmp;
        cin >> tmp;
        if (i < r)
        {
          if (q1.size() < r - l + 1) { q1.push(tmp); }
          else if (q1.top() > tmp) { q1.pop(); q1.push(tmp); }
        }
        if (i >= l-1)
        {
          if (q2.size() < r - l + 1) { q2.push(tmp); }
          else if (q2.top() > tmp) { q2.pop(); q2.push(tmp); }
        }
      }

      ll sum1 = 0;
      while (q1.empty() == false) {
        sum1 += q1.top();
        q1.pop();
      }
      ll sum2 = 0;
      while (q2.empty() == false)
      {
        sum2 += q2.top();
        q2.pop();
      }
      ll sum = (sum1 < sum2) ? sum1 : sum2;
      cout << sum << endl;
    }

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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

#define optimize() ios_base::sync_with_stdio(0); cin.tie(0)
#define ll long long
#define ff first
#define ss second
#define sz size()
#define pb push_back
#define vinput for(auto& x: v) cin >> x;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define range(i,x,y) for(int i=x;i<y;i++)
#define back_range(i,x,y) for(int i=y-1;i>=x;i--)
#define mem(a,b) memset(a, b, sizeof(a) )

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<pii> vii;

// Debug..
#ifdef LOCAL
#include "debug2.h"
#else
#define dg(x...)
#endif

bool comp(const pair<int, int>& a, const pair<int, int>& b) {
    return a.second < b.second;
}

void Solve() {
    int n, k;
    cin >> n >> k;
    vi v(n);
    map<int, int>cnt;
    range(i, 0, n){
        cin >> v[i];
        cnt[v[i]]++;
    }
    int ans = cnt.sz;
    vector<pair<int, int>> v1(all(cnt));
    sort(all(v1), comp);
    for(auto u: v1){
        if(u.ss <= k){
            ans--;
            k -= u.ss;
        }
    }
    cout << (ans == 0 ? 1 : ans) << endl;
    
}

int main() {
    optimize();
    
    int t = 1;
    cin >> t;
    for(int i=1; i<=t; i++){
        //cout << "Case " << i << ": ";
        Solve();
    }
    
    return 0;
}

Solution 2 (runtime: 109 ms):
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define f(i,a) for(ll i = 0; i < a; i++)

int dx[4] = { 0, 0, 1, -1 };
int dy[4] = { 1, -1, 0, 0 };

using namespace std;

ll pow(ll n, ll exp)
{
    if(exp == 0)
    return 1;
    if(exp == 1)
    return n;

    ll half = pow(n, exp / 2);
    
    if(exp%2 == 0)
    return half * half;    
    else
    return n * half * half;
    
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t  = 1;
    cin >> t;   
    while (t--) {
        //unordered_map<ll, ll> mpp;
        bool choice = false;
        ll n = -1, m, k;
        
        cin >> n >> k;
        vector<ll> a(n);
        map<ll, ll> mpp;

        

        for(ll i = 0; i < n; i++)
        {
            cin >> a[i];
            mpp[a[i]]++;
        }
        if(k == n)
        {
            cout << 1 << endl;
            continue;
        }
        priority_queue<ll, vector<ll>, greater<ll>> pq;
        for(auto x : mpp)
        pq.push(x.second);
        
        ll removed = 0;
        while(k>0)
        {
            ll temp = pq.top(); 
            if(k - temp >= 0)
            {
                pq.pop();
                removed++;
            }
            k-=temp;
        }
        cout << pq.size() << endl;
        

        
    }
        return 0;
    }
Problem: 2062C - Cirno and Operations
Language: c++17 

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

#define ll long long

map <vector<ll>, bool> vis;
int n;
ll ret;
void bck(vector <ll> ls, bool rev)
{
	if(vis[ls]) return;
	vis[ls] = 1;
	ll act = 0;
	for(auto u : ls) act += u;
	ret = max(ret, act);

	if((int)ls.size() == 1) return;
	vector <ll> tmp;
	for(int i=1; i<(int)ls.size(); i++)
		tmp.push_back(ls[i]-ls[i-1]);
	bck(tmp,0);

	if(!rev)
	{
		reverse(ls.begin(), ls.end());
		bck(ls,1);
	}
}

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

	int t; cin >> t;
	while(t--)
	{
		cin >> n; vector <ll> ls;
		for(int i=0; i<n; i++)
		{
			ll a; cin >> a;
			ls.push_back(a);
		}
		vis.clear();
		ret = -1e18; bck(ls,0);
		cout << ret << '\n';
	}
}

Solution 2 (runtime: 62 ms):
#include<bits/stdc++.h>
#define LL long long
#define MAXN 300010
#define INF 1000000010
#define MOD 1000000007
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Rof(i,a,b) for (int i=(a);i>=(b);i--)
using namespace std;
LL a[2][MAXN];
void Main(){
    int n;cin>>n;
    For(i,1,n) cin>>a[0][i];
    LL ans=-1LL*INF*INF;
    For(op,0,n-1){
        LL ad=0;bool f=op%2;
        For(i,1,n-op) ad+=a[f][i];
        if (op) ad=abs(ad);
        ans=max(ans,ad);
        For(i,1,n-op-1) a[!f][i]=a[f][i+1]-a[f][i];
    }
    cout<<ans<<"\n";
}
int main(){
    std::ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int T=1;cin>>T;
    while (T--) Main();
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>

#define endl '\n'

#define int long long

#define unmap unordered_map

#define unset unordered_set

#define MAXQ priority_queue

using namespace std;

template<typename T> using MINQ=priority_queue<T,vector<T>,greater<T> >;

using pii=pair<int,int>;

using vi=vector<int>;

using vii=vector<vi>;



int a[100010],b[100010];



void solve(){

	int n,l,r,ans1=0,ans2=0;

	cin>>n>>l>>r;

	for(int i=1;i<=n;i++)cin>>a[i],b[i]=a[i];

	sort(a+1,a+r+1);sort(b+l,b+n+1);

	for(int i=1;i<=r-l+1;i++)ans1+=a[i];

	for(int i=l;i<=r;i++)ans2+=b[i];

	cout<<min(ans1,ans2)<<endl;

	return ;

}



signed main(){

	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);

	int _t=1;

	cin>>_t;

	//cout<<fixed<<setprecision(20);

	for(int i=1;i<=_t;i++){

		//cout<<"Case "<<i<<": ";

		solve();

	}

	return 0;

}

Solution 2 (runtime: 77 ms):
#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef double dd;

typedef pair<ll, ll> ii;

typedef tuple<ll, ll, ll> tp;



#define ff first

#define ss second

#define pb push_back

#define in insert

#define io ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)



const ll mod = (ll)1e9+7;

const ll inf = numeric_limits<int>::max()-5;

const ll INF = (ll)2e18;



void solve()

{

    ll n, l, r;

    cin>>n>>l>>r;

    vector<int> arr(n), a(n), b(n);

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

        cin>>arr[i];

    }

    a = arr;

    b = arr;

    sort(a.begin(), a.begin() + r, greater<>());

    sort(b.begin() + l - 1, b.begin() + n);



    ll sum_1 = 0, sum_2 = 0;

    for(ll i=l-1;i<r;i++){

        sum_1 += a[i];

    }

    for(ll i=l-1;i<r;i++){

        sum_2 += b[i];

    }

    // cout<<"Sum1: "<<sum_1<<" sum2: "<<sum_2<<endl;



    cout<<min(sum_1, sum_2)<<"\n";



    // for(auto &x:a){

    //     cout<<x<<" ";

    // }

    // for(auto &x:a){

    //     cout<<x<<" ";

    // }

}



int main()

{

    io;

    ll T = 1, CT = 0;

    cin>>T;

    while(T--){

        // cout<<"Case "<<++CT<<": ";

        solve();

    }



    return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
const int M=1e9+7;

void solve(){
  int l,r;
  cin>>l>>r;int a,b,c;int ans=0;
  for(int i=30;i>=0;i--){
     int b1=0,b2=0;
     if((l&(1ll<<i))){
        b1=1;
     }
     if((r&(1ll<<i))){
        b2=1;
     }
    if(b1==b2){
        ans+=b1*(1<<i);
    }
    else{
        a=ans+(1ll<<i);
        b=a-1;break;
    }
  }
  for(int i=l;i<=r;i++){
    if(a!=i and b!=i){
        c=i;break;
    }
  }
  cout<<a<<" "<<b<<" "<<c;
  cout<<endl;
}
signed main(){
    int t=1;cin>>t;
  while(t--){
   solve();
  }
}

Solution 2 (runtime: 93 ms):
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    while (n > 0) {
        int a, b, c;
        int left, right;
        cin >> left >> right;
        int k = 31 - __builtin_clz(left ^ right);
        a = left | ((1 << k) - 1);
        b = a + 1;
        c = a == left ? right : left;
        cout << a << " " << b << " " << c << endl;
        --n;
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 390 ms):
#include <bits/stdc++.h>

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int n;

        cin >> n;

        int a[n];

        string ans = "YES";

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

            cin >> a[i];

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

        {

            if (a[i + 1] < a[i])

            {

                ans = "NO";

                break;

            }

            else

            {

                a[i + 1] = a[i + 1] - a[i];

                a[i] = 0;

            }

        }

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

        {

            if (a[i] > a[i + 1])

            {

                ans = "NO";

                break;

            }

        }

        cout << ans << endl;

    }

}

Solution 2 (runtime: 375 ms):
// Online C++ compiler to run C++ program online

#include <iostream>

# include <bits/stdc++.h>

# include <math.h>

using namespace std;







int main() {

int t;

cin >> t;

while(t--){

int n;

cin >> n;

vector<int> vec(n);

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

cin >> vec[i];

}



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

int mini=min(vec[i],vec[i+1]);

vec[i]-=mini;

vec[i+1]-=mini;

}



bool isDec=false;

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

if(vec[i+1]<vec[i]){

isDec=true;

break;

}

}



if(isDec)cout << "NO" << endl;

else cout << "YES" << endl;

}



return 0;

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

Solution 1 (runtime: 46 ms):
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 100010;

LL t , n;
LL a[N];


int main()
{
    cin >> t;

    while( t -- )
    {
        cin >> n;

        LL ans = 0;
        for(LL i = 0 ; i < n ; i ++ ) {cin >> a[i];ans += a[i];}

        
        while( n > 1)
        {   
            LL sum = 0;
            for(LL i = 0;i < n - 1 ; i ++) 
            {
                a[i] = a[i + 1] - a[i];
                sum += a[i];
            }

            ans = max(ans, abs(sum));

            n --;
        }
        
        cout << ans << endl ;
        
    }

    return 0 ;
}

Solution 2 (runtime: 61 ms):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>,
    rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
 
#define pb push_back
#define LSOne(S) (S & (-S))

const int N = 300005, inf = 1e9+10, MOD = 998244353;//1e9+7;
int n;
ll A[N];

void solve(int tc = 1) {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];
    vll V;
    for (int i = 0; i < n; i++) V.pb(A[i]);

    ll ans = 0;
    for (int i = 0; i < n; i++) ans += A[i];
    while (V.size() > 1) {
        ans = max({ans, V.back()-V[0], V[0]-V.back()});
        vll Vtmp;
        for (int i = 1; i < V.size(); i++) Vtmp.pb(V[i]-V[i-1]);
        V = Vtmp;
    }
    ans = max(ans, V[0]);
    cout << ans << endl;
}

void init() {
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    init();
    int tt=1; cin >> tt;
    for (int tc = 1; tc <= tt; tc++) {
        //cout << "Case #" << tc << ": ";
        solve(tc);
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

void solve(){
    int n; cin >> n;
    vector <int> l;
    vector<int> v(n);
    for(int i = 0;  i< n; ++i){
        cin >> v[i];
        l.push_back(i+1);
    }

    vector<pair<int,int>> ans;

    for(int i = n-1; i >= 0; --i){
        auto it = find(l.begin(), l.end(), v[i]);
        int ft  = it - l.begin();
        for(int j  = ft  - 1; j >= 0 ; --j ){
            if(l[j] != -1){
                ans.push_back({l[ft], l[j]});
            }
        }

        for(int j  = 0; j < n ; ++j ){
            if(l[j] != -1 and j != ft){
                ans.push_back({l[j], l[ft]});
            }
        }

        l[ft] = -1;
    }

    cout << ans.size() << '\n';
    for(auto  [x, y]: ans){
        cout << x << " " << y << '\n';
    }
    
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1; //cin >> t;
    while(t--)solve();
    return 0;
}

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








int main(){
    int n;
    cin>>n;
    int arr[n + 1];
    for(int i = 1;i <= n;i++) cin>>arr[i];
    vector<pair<int, int>> ans;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j < i;j++){
            ans.push_back({i, j});
        }
    }
    for(int i = 1;i <= n;i++){
        vector<int> temp;
        for(int j = i + 1;j <= n;j++){
            if(arr[j] > arr[i]) temp.push_back(arr[j]);
             
        }
        sort(temp.begin(), temp.end());
        for(auto x : temp) ans.push_back({arr[i], x});
    }
    cout<<ans.size()<<endl;
    for(auto x : ans) cout<<x.first<<" "<<x.second<<endl;
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

const int MOD=1e9+7;
const ll INF=1e18;

void run_case(){
      int n;
      cin>>n;
      vector<int>a(n);
      for(int i=0;i<n;i++){
        cin>>a[i];
      }
      bool ok=true;
      for(int i=0;i<n-1;i++){
          int mini=min(a[i],a[i+1]);
          a[i]-=mini;
          a[i+1]-=mini;
      }
      for(int i=0;i<n-1;i++){
        if(a[i]>a[i+1]){
            ok=false;
        }
      }
      if(ok){
        cout<<"YES"<<endl;
      }
      else{
        cout<<"NO"<<endl;
      }
      
      





}

int main(){
      cin.tie(0)->sync_with_stdio(0);
       int tt;
       cin>>tt;
       
       while(tt--){
           run_case();
       }
}

Solution 2 (runtime: 359 ms):
#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;







int main() {

int t;

cin >> t;



while (t--) {

int n;

cin >> n;



vector<int> v(n);

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

cin >> v[i];

}



int i=0;

bool c=false;

while(i<n-1){

if(v[i]>v[i+1]){

c=true;

break;

}

else{

v[i+1]-=v[i];

v[i]=0;



}

i++;

}



if (c) {

cout << "no" << endl;

} else {

cout << "yes" << endl;

}

}



return 0;

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

Solution 1 (runtime: 62 ms):
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <cmath>
#include <queue>
#include <tuple>
using namespace std;

vector<long long> diff(vector<long long> arr){
    vector<long long> ans(arr.size() - 1);
    for (int i = 0; i < ans.size(); i++){
        ans[i] = arr[i+1] - arr[i];
    }
    return ans;
}
void solve(){
    int n;
    cin >> n;
    vector<long long> arr(n);
    long long ans = 0;
    for (int i = 0; i < n; i++){
        cin >> arr[i];
        ans += arr[i];
    }
    for (int i = 0; i < n - 1; i++){
        ans = max(ans, 1LL * abs(arr[arr.size() - 1] - arr[0]));
        arr = diff(arr);
    }
    cout << ans << "\n";
}

int main(){
    int t;
    cin >> t;
    for (int i = 0; i < t; i++){
        solve();
    }
    return 0;
    
}

Solution 2 (runtime: 61 ms):
#pragma optimize("O3")

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        vll nums(n);
        for (int i = 0; i < n; i++) {
            cin >> nums[i];
        }

        ll ans = 0;
        for (auto x : nums)
            ans += x;

        while (nums.size() > 1) {
            vll new_nums;
            ll sum = 0;
            for (int i = 0; i < nums.size() - 1; i++) {
                ll diff = nums[i + 1] - nums[i];
                sum += diff;
                new_nums.push_back(diff);
            }
            ans = max(ans, abs(sum));
            nums = new_nums;
        }

        cout << ans << endl;
    }
}