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

Solution 1 (runtime: 78 ms):
// Away... beyond all concepts of wrong-doing and right-doing
// There is a field, I will meet you there.


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
 
typedef long long ll;
#define pb push_back
#define endl '\n'
#define rev(v) reverse(v.begin(), v.end())
#define srt(v) sort(v.begin(), v.end())
#define minv(v) *min_element(v.begin(), v.end())
#define maxv(v) *max_element(v.begin(), v.end())
#define vll vector<ll>
#define pll = pair<ll, ll>;

const ll mod = 1000000007;
const ll MOD = 998244353;

void vin(vector<ll> &a, int n)
{
    for (int i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        a.push_back(x);
    }
}

ll modPow(ll base, ll exp, ll mod) {
    ll result = 1;
    base %= mod;
    while (exp > 0) {
        if (exp & 1) result = (result * base) % mod;
        base = (base * base) % mod;
        exp >>= 1;
    }
    return result;
}

ll modInverse(ll x, ll mod) {
    return modPow(x, mod - 2, mod);
}

void solve() {
    ll n, l, r; cin>>n>>l>>r;
    l--; r--;
    ll cnt = r-l+1;
    vll a; vin(a, n);
    ll ans1 = 0; ll ans2 = 0;
    vll v1, v2;
    for (ll i = 0; i<=r; i++) v1.push_back(a[i]);
    for (ll i = l; i<n; i++) v2.push_back(a[i]);
    srt(v1); srt(v2);
    for (ll i = 0; i<cnt; i++){
        ans1 += v1[i]; ans2 += v2[i];
    }
    cout<<min(ans1, ans2)<<endl;

}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll t=1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 186 ms):
#include <algorithm>

#include <climits>

#include <cmath>

#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main() {

  int t;

  cin >> t;

  for (int w = 0; w < t; w++) {

    int n, l, r;

    cin >> n >> l >> r;

    vector<int> A(n);

    vector<int> B(r);

    vector<int> C(n - l + 1);

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

      cin >> A[i];

    }

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

      B[i] = A[i];

    }

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

      C[i - l + 1] = A[i];

    }

    sort(B.begin(), B.end());

    sort(C.begin(), C.end());

    long long int res = LLONG_MAX;

    long long int temp = 0;

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

      temp += B[i];

    }

    res = min(res, temp);

    temp = 0;

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

      temp += C[i];

    }

    res = min(res, temp);

    cout << res << endl;

  }

  return 0;

}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double lld;
#define PI 3.14159265358979323846
#define MOD 1000000007
#define INF 1e18
#define endl "\n"

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // *find_by_order(index), order_of_key(val)

#ifndef ONLINE_JUDGE
    #include <E:\CP\debug.h>
#else
#define debug(x)
#endif

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

    // freopen("inputFileName.txt", "r", stdin);
    // freopen("outputFileName.txt", "w", stdout);

    ll t; cin >> t;
    while(t--) {
        string s;
        cin >> s;
        ll n = s.length();
        for(ll i = 0; i < min(n, (ll)10); i++) {
            for(ll j = i+1; j >= 1; j--) {
                if(s[j-1] < s[j] - 1) {
                    s[j] = s[j] - 1;
                    swap(s[j], s[j-1]);
                }
            }
        }
        for(ll i = 0, j = i+10; j < n; j++, i++) {
            for(ll k = j; k >= i+1; k--) {
                if(s[k-1] < s[k] - 1) {
                    s[k] = s[k] - 1;
                    swap(s[k], s[k-1]);
                }
            }
        }
        cout << s << endl;
    }

    return 0;
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long 

int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll t;
    cin>>t;
    while(t--){
        string inp;
        cin>>inp;
        ll n=inp.length();
        for(ll i=0;i<n;i++){
            int maxm=(inp[i]-'0');
            int index=i;
            for(ll j=i+1;j<min(n,i+9);j++){
                if(maxm<((inp[j]-'0')-j+i)){
                    maxm=((inp[j]-'0')-j+i); 
                    index=j;
                }
            }
            if(index!=i){
                for(int k=index;k>i;k--){
                    inp[k]=inp[k-1];
                }
                inp[i]=(maxm+'0');
            }
        }
        cout<<inp<<endl;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 124 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin>>t;
	
	while(t--){
        string x;
		cin>>x;
		for(int i=0;i<x.size()-1;i++){
			if(x[i]<x[i+1]-1){
				swap(x[i],x[i+1]);
				x[i]--;
				if(i>=1)
				i-=2;
			}
		}
		cout<<x<<'\n';
	}
}

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

signed main()
{
     int t;
     cin >> t;

     for (int _ = 0; _ < t; _++){
          string x;
          cin >> x;
          int l = x.size();
          int n[l];
          for (int i = 0; i < l; i++){ n[i] = x[i] - '0'; }

          for (int f = 0; f < l; f++){
               int bestV = n[f];
               int bestVpos = f;

               for (int i = f+1; (i < l && i <= (f + (8 - n[f]))); i++){
                    int aux = n[i] - (i - f);
                    if(aux > bestV){
                         bestV = aux;
                         bestVpos = i;
                    }
               }
               for (int i = bestVpos; i > f; i--){ n[i] = n[i-1]; }
               n[f] = bestV;
          }
          
          for (int i = 0; i < l; i++){ cout << n[i]; }
          cout << endl;
     }
}

/*
1
5891917899
*/
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
const int mod=1e9+7;
int dx[8]={-1,0,0,1,-1,-1,1,1};
int dy[8]={0,-1,1,0,-1,1,-1,1};

void nishant2526(){
  int n;
  cin>>n;
  vector<int> arr(n);
  for(int i=0;i<n;i++){
    cin>>arr[i];
  }
  for(int i=1;i<n;i++){
    if(arr[i-1]>arr[i]){
      cout<<"NO"<<endl;
      return;
    }
    else{
      arr[i]-=arr[i-1];
      arr[i-1]=0;
    }
  }
  cout<<"YES"<<endl;
    
   
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  int tt;
  cin >> tt;
  while (tt--)
  {
    nishant2526();
  }

  return 0;
}


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



using namespace std;



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int t;

    cin >> t;

    while(t != 0){

        -- t;

        int n;

        cin >> n;

        int a, b, check = 1;

        cin >> a;

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

            cin >> b;

            if(a <= b){

                a = b - a;

            }

            else{

                check = 0;

            }

        }

        if(check == 1) cout << "YES" << endl;

        else cout << "NO" << endl;

    }

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

void func(string s,int n){
    int sum=0;
    int num_2=0;
    int num_3=0;
    for(int i=0;i<n;i++){
        sum += s[i]-'0';
        if(s[i]=='2'){
            num_2++;
        }
        if(s[i]=='3'){
            num_3++;
        }
    }
    bool flag = false;
    for(int i=0;i<=num_2&&i<9;i++){
        for(int j=0;j<=num_3&&j<9;j++){
            int a=2*i+6*j;
            // since change 2 to its square will increase the sum by 2 and 3 will increase by 6
            int final_sum = sum+a;
            if(final_sum%9==0){
                flag=true;
            }
            if(flag){
                break ;
            }
        }
        if(flag){
            break;
        }
    }
    if(flag){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

int_fast32_t main(){
    int t;                                                                                                                                                          
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int n=s.length();
        func(s,n);
    }
    return 0;
}                                                                                                                                                                                                                                                                               

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

#include<queue>

using namespace std;

int main() {

	int n; 

	string s;

	cin >> n;

	while (n--) {

		queue<int>q,qq;

		int a[10] = { 0 },sum=0;

		cin >> s;

		for (int i = 0;i < s.size();i++) {

			a[s[i] - '0']++;

			sum += s[i] - '0';

		}

		sum %= 9;

		sum = 9 - sum;

		if (sum == 9) { cout << "YES"<<endl;continue; }

		int check[10] = { 1 };

		int fir = 0, sec = 6;

		for (int i = 0;i < a[2];i++) {

			fir = (fir + 2) % 9;

			check[fir]++;

		}

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

			if (check[i])q.push(i);

		for (int i = 0;i < a[3];i++) {

			while (q.size()) {

				int now = (q.front() + 6) % 9;

				check[now]++;

				qq.push(now);

				q.pop();

			}swap(q, qq);

		}

		if (check[sum])cout << "YES" << endl;

		else cout << "NO" << endl;

	}

}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
const int N=1e7+2;

void solve(){
  string a,b,c;
  cin >>a>>b>>c;
  int m=a.size();
  int n=b.size();
  int o=c.size(); 
  vector<vector<int>> dp(n+1,vector<int>(m+1,0));
  for(int i=1; i<=n; i++){
	if(b[i-1]==c[i-1]){
		dp[i][0]=dp[i-1][0]+1;
	}
	else {
            dp[i][0] = dp[i - 1][0];
        }
  }
  for(int i=1; i<=m; i++){
	if(a[i-1]==c[i-1]){
		dp[0][i]=dp[0][i-1]+1;
	}
	else {
            dp[0][i] = dp[0][i - 1];
        }
  }
  for(int i=1; i<=n; i++){
	for(int j=1; j<=m;j++){
		int pos = i + j - 1; // Current position in c
            dp[i][j] = max(
                dp[i - 1][j] + (b[i - 1] == c[pos] ? 1 : 0), // Match with b
                dp[i][j - 1] + (a[j - 1] == c[pos] ? 1 : 0)  // Match with a
            );
	}
  }
  cout<<o-dp[n][m]<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int t;
  cin>>t;
  while(t--){
 
      solve();
  }
   
    return 0;
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define endl "\n"

const int mod=998244353;
const int MOD=1000000007;
const int INF=1e18;

int pow1(int a,int b,int mod){
    int ans=1;
    while(b){
        if(b&1){
            ans=(ans*a);
            ans%=mod;
        }
        a=(a*a);
        a%=mod;
        b>>=1;
    }
    return ans%mod;
}

int pow2(int a,int b){
    int ans=1;
    while(b){
        if(b&1){
            ans=(ans*a);
        }
        a=(a*a);
        b>>=1;
    }
    return ans;
}

void solve() {
    string a,b,c;
    cin>>a>>b>>c;
    int n=a.size();
    int m=b.size();
    vector<vector<int> >dp(n+1,vector<int>(m+1,n+m));
    dp[0][0]=0;
     for (int i = 0; i < n; i++) {
        dp[i + 1][0] = dp[i][0] + (a[i] != c[i]);
    }
    for (int j = 0; j < m; j++) {
        dp[0][j + 1] = dp[0][j] + (b[j] != c[j]);
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            dp[i][j]=min(dp[i][j],(a[i-1]!=c[i+j-1])+dp[i-1][j]);
            dp[i][j]=min(dp[i][j],(b[j-1]!=c[i+j-1])+dp[i][j-1]);
        }
    }
    cout<<dp[n][m]<<endl;
}
int32_t main() {
       ios::sync_with_stdio(false);
   cin.tie(0);
    int t;
    cin>>t;
    while(t--)
        solve();
    
    
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 359 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define ss second
#define ff first
#define pb push_back
#define vi vector<int>
#define pii pair<int, int>
#define vl vector<ll>
#define pll pair<ll, ll>
#define f(i, j, k, l) for (ll i = j; i < k; i += l)
#define yes cout << "YES\n";
#define no cout << "NO\n";

const db pi = 3.14159265359;
const ll mod = 998244353;
const db EPS = 0.000000001; // 1e-9
const ll inf = (ll)1e18;
const size_t NOT_FOUND = string::npos;
const int REMOVE_LENGTH = 1;
const int MAP_IE_LENGTH = 4;
const int MAP_LENGTH = 2;
const int PIE_LENGTH = 2;

ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

bool isPrime(int n) {
    if (n == 1 || n == 0)
        return false;

    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}

ll sumOfDigits(ll n){
    ll sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    return sum;
}
int countSubstring(const std::string& str, const std::string& sub)
{
    if (sub.length() == 0) return 0;
    int count = 0;
    for (size_t offset = str.find(sub); offset != std::string::npos;
     offset = str.find(sub, offset + sub.length()))
    {
        ++count;
    }
    return count;
}
int countChar(const std::string& str, char ch) {
    int count = 0;
    for (char c : str) {
        if (c == ch) {
            count++;
        }
    }
    return count;
}
//char le[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm','n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
 //char l[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M','N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
//priority_queue<int> q;
int main() {
    int t;
    cin >> t;
    while (t--) {
        ll n;
        cin >> n;
        ll a[n];
        f(i,0,n,1) {
            cin>>a[i];
        }
        if (a[0]>a[1]) {
            cout<<"NO"<<endl;
        }
        else {
            ll c=0;
            ll b=a[0];
            f(i,1,n-1,1) {
                if (a[i]>a[i+1]&&a[i]-b>a[i+1]) {
                    c=1;
                }
                else {
                    b=a[i]-b;
                }
            }
            if (c==0) {
                cout<<"YES"<<endl;
            }
            else {
                cout<<"NO"<<endl;
            }

        }
    }

    return 0;
}


Solution 2 (runtime: 328 ms):
#include <bits/stdc++.h>
using namespace std;
void solve(){
    int n;
    cin>>n;
    vector<int>v(n);
    for(int &i:v)cin>>i;
    for(int i=0;i<n-1;i++){
        int x=min(v[i], v[i+1]);
        int z=max(v[i], v[i+1]);
        if(v[i]==z&&v[i]>v[i+1]){
            cout<<"NO"<<endl;
            return;
        }else{
            v[i+1]=v[i+1]-x;
        }
    }

    cout<<"YES"<<endl;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define ab adityabelgaonkar
using namespace std;

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

    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);
        for (auto &i : a)
            cin >> i;

        for (int i = 0; i < n - 1; ++i)
        {
            int minel = min(a[i], a[i + 1]);
            a[i] -= minel;
            a[i + 1] -= minel;
        }

        if (is_sorted(a.begin(), a.end()))
            cout << "YES\n";
        else
            cout << "NO\n";
    }

    return 0;
}

// 4 3 2 1
// 1 0 2 1
// 1 0 1 0
// 0 0 0 0
// 4 5 2 3
// 0 1 0 1
// 0 0 0 0

// 4 3 2 1

// 1 2 3 4 5
// 0 0 0 0 1
// 4 3 2 1
// 9 9 8 2
// 0 0 8 2

// 1 2 4 3
// 0 1 4 3
// 0 0 3 3

Solution 2 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
void sol(){
	int n;
	cin>>n;
	int a[n+10];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	a[0]=0;
	int cnt=0;
	for(int i=1;i<n;i++){
		if(a[i]>a[i+1])cnt=i;
	}
	if(cnt==0) cout<<"Yes"<<endl;
	else {
		for(int i=0;i<=cnt;i++){
			a[i+1]-=a[i];
			a[i]=0;
			if(a[i+1]<0){
				cout<<"No"<<endl;
				return ;
			}
		}
		cout<<"Yes"<<endl;
	}
}
int main(){
	ios;
	int t=1;
	cin>>t;
	while(t--) sol();
	
	return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

using namespace std;

#define int long long
#define pb push_back
#define FORI(sti, n) for(int i=(sti); i<(n); i++)
#define FORJ(stj, n) for(int j=(stj); j<(n); j++)
#define FORK(stk, n) for(int k=(stk); k<(n); k++)
#define tvi(v) FORI(0, (v).size()) cerr << (v)[i] << " "; cerr << "\n";
#define tii(val) cerr <<  "(" << (val).first << ", " << (val).second << ")\n";
#define tvii(v) FORI(0, (v).size()) { tii((v)[i]) } cerr << "\n";
#define tvvi(v) FORI(0, (v).size()) { FORJ(0, (v)[i].size()){ cerr <<  v[i][j] << " "; } cerr << "\n"; }  
#define all(v) (v).begin(), (v).end() 
#define rall(v) (v).rbegin(), (v).rend() 

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vbl;



void solve(){
	int n, l, r;
	cin >> n >> l >> r;
	vi v(n);
	for(auto &a: v) cin >> a;

	vi store, numbers, pt1, pt2;
	int npt1=0;
	int npt2=0;

	for(int i=0; i<n; i++){
		if(i>=(l-1) && i<=(r-1)){
			store.pb(v[i]);
		}
		else{
			if(i<(l-1)){ 
				pt1.pb(v[i]); npt1+=v[i]; 
			}
			else{ 
				pt2.pb(v[i]); npt2+=v[i]; 
			}
		}
	}
	
	sort(rall(store));
	vi store2 = store;
	sort(all(pt1));
	sort(all(pt2));

	int ans1=0, ans2=0, idx1=0, idx2=0;	
	for(int i=0; i<store.size(); i++){
		if(idx1<pt1.size() && store[i]>pt1[idx1]){
			store[i]=pt1[idx1];
			idx1++;
		}

		if(idx2<pt2.size() && store2[i]>pt2[idx2]){
			store2[i]=pt2[idx2];
			idx2++;
		}

		ans1+=store[i];
		ans2+=store2[i];
	}

	cout << min(ans1, ans2) << "\n";
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	
	int t; cin >> t; while(t--)
		solve();

    return 0;
}


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

using namespace std;



int main() 

{

    long long t;

    cin >> t;

    while (t--) {

        long long n, l, r;

        cin >> n >> l >> r;

        vector<long long> arr(n);

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

            cin >> arr[i];

        }

        l--;

        r--;

        multiset<long long> s1, s2;

        for (long long i = 0; i <= r; i++) {

            s1.insert(arr[i]);

        }

        for (long long i = l; i < n; i++) {

            s2.insert(arr[i]);

        }

        long long sum1 = 0, sum2 = 0;

        long long k = r - l + 1;

        long long ct1 = 0;

        for (auto i : s1) {

            if (ct1 == k) {

                break;

            }

            sum1 += i;

            ct1++;

        }

        ct1 = 0;  

        for (auto i : s2) {

            if (ct1 == k) {

                break;

            }

            sum2 += i;

            ct1++;

        }

        cout << min(sum1, sum2) << endl;

    }

}
Problem: 2050D - Digital string maximization
Language: c++17 

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

void solve(){
    string s;cin>>s;
    int n = s.length();

    for(int i=0;i<n-1;i++){
        
        int best = (s[i]-'0');
        int pos = i;
        int cnt = 1;
        for(int j=i+1;j<min(i+9, n);j++){
            int val = s[j]-'0'-cnt;
            if(best < val){
                best = val;
                pos = j;
            }
            cnt++;
        }

        for(int j=pos;j>i;j--){
            s[j] = s[j-1];
        }
        s[i] = char(best + '0');
    }

    cout<<s<<endl;
}

signed main()
{
    int t = 1;
    cin>>t;
    while (t--){
        solve();
    }
    return 0;
}

Solution 2 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 200000
#define mod 1000000007



void solve(){
    string s;
    cin>>s;
    ll n=s.size();
    ll flag;
    for (int i=1;i<n;i++){
        while(i>0 && ((s[i]-s[i-1])>1) && s[i]>'0'){
            s[i]--;
            swap(s[i],s[i-1]);
            i--;
        }
    }
    cout<<s<<endl;
}


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <array>
#include <unordered_map>
#include <climits>

using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define fr(i, a, b) for (int i = a; i < b; i++)
#define all(a) a.begin(), a.end()

int mod = 1e9 + 7;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int tt = 1;
    cin >> tt;
    while (tt--)
    {
    
    int n;
    cin >> n;
    vll a(n);
    fr(i, 0, n)
    {
        cin >> a[i];
    }
    bool poss = true;
    fr(i, 1, n)
    {
        if(a[i] >= a[i - 1])
        {
            a[i] = a[i] - a[i - 1];
            a[i - 1] = 0;
        }
        else if(a[i] < a[i - 1])
        {
            poss = false;
            break;
        }
    }
    if(poss)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    }
}

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

using namespace std;



int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int n;

        cin >> n;

        int arr[n];

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

        {

            cin >> arr[i];

        }

        if (is_sorted(arr, arr + n))

            cout << "YES" << endl;

        else

        {

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

            {

                int m = min(arr[i], arr[i + 1]);

                arr[i] = arr[i] - m;

                arr[i + 1] = arr[i + 1] - m;

            }

            if (is_sorted(arr, arr + n))

            {

                cout << "YES" << endl;

            }

            else if (!is_sorted(arr, arr + n))

            {

                cout << "NO" << endl;

            }

        }

    }

    return 0;

}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 186 ms):
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int t; cin>>t;
	while (t--)
	{
		int n,l,r; cin>>n>>l>>r;
		long long ans=0;
		int a[100001];
		for (int i=1;i<=n;i++) cin>>a[i];
		for (int i=l;i<=r;i++) ans=ans+a[i];
		sort(a+1,a+l); sort(a+l,a+r+1); sort(a+r+1,a+n+1);
		int ll=1,rr=r;
		long long s1=0,s2=0;
		while ((ll<l)&&(rr>=l)&&(a[ll]<a[rr]))
		{
			s1+=a[rr]-a[ll]; ll++; rr--;
		}
		ll=r; rr=r+1;
		while ((ll>=l)&&(rr<=n)&&(a[ll]>a[rr]))
		{
			s2+=a[ll]-a[rr]; ll--; rr++;
	    }
		if (s1>s2) ans-=s1; else ans-=s2;
		printf("%lld\n",ans);
	}
	return 0;
}


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

int main(){
    int t;
    cin >> t;
    while(t--){
        int n, l, r;
        cin >> n >> l >> r;
        vector<int> arr(n + 1);
        for(int i = 1; i <= n; i++){
            cin >> arr[i];
        }
        vector<int> left;
        vector<int> right;
        for(int i = 1; i <= r; i++){
            left.push_back(arr[i]);
        }
        for(int i = l; i <= n; i++){
            right.push_back(arr[i]);
        }
        sort(left.begin(), left.end());
        sort(right.begin(), right.end());
        long long int ans1 = 0;
        long long int ans2 = 0;
        for(int i = 0; i < r - l + 1; i++){
            ans1 += left[i];
            ans2 += right[i];
        }
        cout << min(ans1, ans2) << endl;
    }
}