ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: c++17 

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

void jassi () {
    string s;
    cin>>s;
    int n= s.size();
    string ans = "";
    for (int i = 0; i < n; i++) {
        if (s[i] > '7') ans.push_back(s[i]);
        else {
            int l = 8 - (s[i] - '0');
            int diff = s[i] - '0', in = -1;
            for (int j = i+1;j<min(n, i+1+l);j++) {
                if ((s[j] - '0') - (j-i) > diff) {
                    diff = (s[j] - '0') - (j-i);
                    in = j;
                }
            }
            if (in != -1) {
                ans.push_back(diff + '0');
                s.erase(in, 1);
                i--;
            }
            else ans.push_back(s[i]);
        }
        if (ans.size() == n) break;
    }
    cout<<ans<<"\n";
    return;
}

int32_t main () {
    int t;
    cin>>t;
    while (t--) {
        jassi();
    }
}

Solution 2 (runtime: 77 ms):
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <math.h>
#include <stdio.h>

using namespace std;
int sov(){
    int ma=-100, pos;
    string a , ans;
    cin>>a;
    for(int i = 0 ; i < a.size(); i++){
        for (int j = i  ; j<min(i+10 ,int(a.size())) ; j++){
            if(ma < (a[j]-'0') - (j-i)){
                ma = (a[j]-'0') - (j-i);
                pos = j;
            }
        }

    a[pos]=0;
    while (pos > i) {
            swap(a[pos], a[pos - 1]);
            pos--;
    }
    ans.push_back(char(ma+'0'));
    ma=-100;
    }
    cout<<ans<<'\n';
    return 0;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long t;
    cin>>t;
    for (long long i=0; i<t;i++){
        sov();
    }
    //3for (long long i=0; i<t;i++){
  //      cout << ans[i]<<endl;
//    }

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

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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
    cin >> n;
    vector<long long> arr(n);
    long long maxSum = 0;
 
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        maxSum += arr[i];
    }
 
    vector<long long> diffArray(n + 1, 0);
 
    for (int step = 1; step < n; step++) {
        maxSum = max(maxSum, abs(arr[n - step] - arr[0]));
        for (int j = 0; j < n - step; j++) {
            diffArray[j] = arr[j + 1] - arr[j];
        }
        for (int j = 0; j < n - step; j++) {
            arr[j] = diffArray[j];
        }
    }
 
    cout << maxSum << endl;
    }
}


Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define NITRO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define endl "\n"
typedef long long ll;
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

vector<ll> GetDifferenceVec(vector<ll> &v)
{
    ll i;
    vector<ll> nxvec;
    for(i=1;i<v.size();i++)
    {
        ll dif = v[i]-v[i-1];
        nxvec.push_back(dif);
        //cout<<dif<<"  dddd"<<endl;
    }
    return nxvec;
}

int main()
{
    NITRO;
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    int t=1,h=1;
    cin>>t;
    while(t--)
    {
        ll i,n;
        cin>>n;
        vector<ll>a(n);
        ll sm=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            sm+=a[i];
        }
        if(n==1)
        {
            cout<<a[0]<<endl;
            continue;
        }
        ll ans = sm;
        vector<ll> ab = GetDifferenceVec(a);
        a=ab;
        while(a.size()>=1)
        {
            vector<ll>ab = GetDifferenceVec(a);
            //cout<<a.size()<<"  aaaa"<<endl;
            sm=0;
            for(i=0;i<a.size();i++)
            {
                sm+= a[i];
            }
            ans = max(ans, abs(sm));
            if(ab.size()<1) break;
            a = ab;
        }
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

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

using namespace std;
#define ll long long
ll a[1010];
void solve(){
    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++){
        ll sum = 0;
        for(int i = 1; i<=now; i++) 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<<'\n';
}

/*
1
2
-1 -1

*/

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


Solution 2 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t; cin>>t; while(t--){
        long long n; cin>>n;
        long long ans=INT_MIN;
        long long sum=0;
        vector<long long> nums(n+1,0);

        for(int i=1; i<nums.size(); i++){
            cin>>nums[i];
            sum+=nums[i];
        }

        ans=sum;
        int i=1;

        while(i<n){

            ans=max(ans,abs(nums[n]-nums[i]));

            for(int j=n; j>i; j--)
            nums[j]=nums[j]-nums[j-1];

            i++;
        }

        ans=max(ans,nums[n]);
        cout<<ans<<endl;
    }
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

int t,n,cnt1,cnt2,a[200010];

int main(){
	scanf("%d",&t);
	while(t--){
		cnt1 = cnt2 = 0;
		scanf("%d",&n);
		for(int i = 1;i <= n;i++){
			scanf("%d",&a[i]);
			if(i != 1){
				if(a[i] > a[i - 1]){
					cnt1++;
				}else{
					cnt2++;
				}
			}
//			if(i > 2){
//				if(a[i] < a[i - 1]){
//					int mn = min(a[i - 1],a[i - 2]);
//					a[i - 1] -= mn;
//					a[i - 2] -= mn;
//				}
//			}
		}
		if(cnt1 >= cnt2){
			printf("Yes");
		}else{
			printf("No");
		}
		puts("");
//		while(1){
//			bool bol = false;
//			for(int i = n;i >= 3;i--){
//				if(a[i] < a[i - 1]){
//					int mn = min(a[i - 1],a[i - 2]);
//					a[i - 1] -= mn;
//					a[i - 2] -= mn;
//					if(mn != 0){
//						bol = true;
//					}
//				}
//			}
//			if(!bol){
//				break;
//			}
//		}
//		bool bol = true;
//		for(int i = 2;i <= n;i++){
//			if(a[i] < a[i - 1]){
//				bol = false;
//				break;
//			}
//		}
//		if(bol){
//			printf("Yes");
//		}else{
//			printf("No");
//		}
//		puts("");
	}
	return 0;
}

Solution 2 (runtime: 327 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll t,n,m;
    bool b;
    cin>>t;
    while(t--)
    {
      b=1;
      ll maxi=-1e9;
      cin>>m;
      vector<ll>v(m);
      for(int i=0;i<m;i++)
      cin>>v[i];
      if(is_sorted(v.begin(),v.end()))
      cout<<"YES"<<endl;
      else
      {
        for(int i=0;i<m-1;i++)
        {
         ll mini=min(v[i],v[i+1]);
         v[i]-=mini;
         v[i+1]-=mini;
        }
        if(is_sorted(v.begin(),v.end()))
        cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
      }
    }
}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

int main() {
    long long t; cin >> t;
    while (t--) {
        string s; cin >> s;
        long long p2 = 0;
        long long p6 = 0;
        long long ts = 0;
        for (long long i = 0; i < s.size(); ++i) {
            if (s[i] == '2') { ++p2; }
            if (s[i] == '3') { ++p6; }
            ts += s[i] - '0';
        }
        
        // 7 -> 9 -> 18 -> 27
        //   +2  +11   +20
        
        if (ts % 9 != 0) {
            long long nakop = 9 - ts % 9;
            if (nakop % 2 != 0) nakop += 9;
            while (nakop > 0 && (p2 > 0 || p6 > 0)) {
                if (p6 > 0 && nakop >= 6) {
                    nakop -= 6;
                    --p6;
                } else if (p2 > 0) {
                    nakop -= 2;
                    --p2;
                } else {
                    break;
                }
            }
            if (nakop == 0) {
                cout << "YES" << endl;
            } else {
                cout << "NO" << endl;
            }
        } else {
            cout << "YES" << endl;
        }
    }
}


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

#define int long long

using namespace std;



int32_t main() {

    int t;

    cin >> t;

    while(t--){

        string s;

        cin>>s;

       long long currSum=0;

       unordered_map<int,int>mpp(10);

        long long two=0,three=0;

        for(auto& c:s){

            currSum+=c-'0';

            if(c=='2') two++;

            if(c=='3') three++;

        }

       mpp[2]=two;

       mpp[3]=three;

        if(currSum%9==0){

            cout<<"YES"<<endl;

            continue;

        }

        int sum=currSum;

        

           

           bool lolu=false;

           //n=x;

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

               for(int j=0;j<=mpp[3];j++){

                   if((sum+i*2+j*6)%9==0){

                       lolu=true;

                       break;

                   }

               }

               if(lolu) break;

           }

           //cerr<<sum<<"\n";

           

           if(lolu) cout<<"YES\n";

           else cout<<"NO\n";

       }

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

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

const int MAXN = 100005;
long long num[MAXN];

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n, l, r;
        long long ans = 0;
        long long res_l = 0;
        long long res_r = 0;
        scanf("%d %d %d", &n, &l, &r);
        for (int i = 1; i <= n; i++) {
            scanf("%lld", &num[i]);
        }
        
        sort(num + 1, num + l);
        sort(num + l, num + r + 1);
        sort(num + r + 1, num + n + 1);
        
        for (int i = l; i <= r; i++) {
            ans += num[i];
        }
        
        for (int i = 1; i <= l - 1 && r - i + 1 >= l; i++) {
            if (num[i] < num[r - i + 1]) {
                res_l += num[r - i + 1] - num[i];
            } else {
                break;
            }
        }

        for (int i = 1; i + r <= n && r - i + 1 >= l; i++) {
            if (num[i + r] < num[r - i + 1]) {
                res_r += num[r - i + 1] - num[i + r];
            } else {
                break;
            }
        }
        ans = min(ans - res_l, ans - res_r);
        printf("%lld\n", ans);
    }

    return 0;
}

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

#define int long long

using namespace std;





signed main()

{

    int t;

    cin>>t;

    while(t--)

    {

        int n,l,r;

        cin>>n>>l>>r;

        vector<int> a(n+1);

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

        {

            cin>>a[i];

        }

        vector<int> b,c;

        for(int i=1;i<=r;i++)

        {

            b.push_back(a[i]);

        }

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

        {

            c.push_back(a[i]);

        }

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

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

        int sum1=accumulate(b.begin(),b.begin()+r-l+1,0LL);

        int sum2=accumulate(c.begin(),c.begin()+r-l+1,0LL);

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

    }   

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

Solution 1 (runtime: 77 ms):
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
using namespace std;


string s;

void sort(int l,int r) {

    int k = r;
    for (int i = l;i<=r;i++) {
        k--;
        for (int j = l;j<=k;j++) {
            if (s[j] < s[j+1]-1) {
                s[j] = s[j] xor s[j+1];
                s[j+1] = s[j] xor s[j+1];
                s[j] = s[j] xor s[j+1];
                s[j]--;
            }
        }
    }
}

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

    for (int i = 0;i<n;i++) sort(i,i+min(n-i-1,9));
    cout << s << '\n';
}


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

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

using namespace std;

int main(){

int t;

cin>>t;

while(t--){

string s;

cin>>s;

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

int ind=i;

while(ind>0 && s[ind]!='0' && (s[ind]-1)>s[ind-1]){

s[ind]--;

swap(s[ind],s[ind-1]);

ind--;

}

}

cout<<s<<endl;

}

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

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<ll> a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        if (n == 1) {
            cout<<a[0]<<endl;
            continue;
        }
        int temp = n;
        ll maxi = accumulate(a.begin(), a.end(), 0LL);
        while (temp > 1) {
            ll sum = 0;
            for (int i = 0; i < temp - 1; i++) {
                a[i] = a[i + 1] - a[i];
                sum += a[i];
            }
            maxi = max(abs(sum), maxi);
            temp--;
        }
        cout<<maxi<<endl;
    }
    return 0;
}


Solution 2 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PII pair<int, int>
#define Pll pair<ll, ll>
#define endl '\n'
const int N = 1010;

void solve()
{
    ll n;
    cin >> n;
    ll a[N];
    for (int i = 1; i <= n; i ++ ) cin >> a[i];
    int now = n;
    ll ans = -1e18;
    for (int i = 1; i <= n; i ++)
    {
        ll 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 << '\n';
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while(T--)
    {
        solve();
    }
}
Problem: 2062C - Cirno and Operations
Language: c++17 

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

int main(){
    ll t; cin >> t; 
    while(t--){
        ll n; cin >> n; 
        vector<ll> v(n); 
        for(ll i=0; i<n; i++){
            cin >> v[i]; 
        }   

        if(v.size() == 1){
            cout << v[0] << "\n"; 
            continue; 
        }

        ll ans = -inf; 
        ll counter = 0; 
        do{
            ll sum = 0; 
            for(ll i=0; i<v.size(); i++){
                sum += v[i]; 
            }
            if(counter == 0) ans = max(ans, sum); 
            else ans = max(ans, abs(sum)); 

            for(ll i=0; i<v.size()-1; i++){
                v[i] = v[i+1] - v[i]; 
            }
            v.pop_back();
            counter = 1;  
        }
        while(v.size() > 0); 

        cout << ans << "\n"; 
    }

}






Solution 2 (runtime: 46 ms):
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define ld long double
#define pll pair<ll,ll>
#define pllv pair<ll,vector<ll>>
#define all(a) a.begin(),a.end()
#define ump unordered_map
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define DEATH_NOTE ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define rep(a,b) for(ll i=a;i<b;i++)
//const ll sz=1001;
const ll mod=1e9+7;
const ll INF=1e18+10;

void solve()
{
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll ans = -INF;
    for(ll i=0;i<n;i++) cin>>a[i];
    vector<ll> v = a;
    if(v.size()== 1) {
        cout<<v[0]<<endl;
        return;
    }
    while(v.size()>1) {
        ll stSum = 0;
        for(ll i=0;i<v.size();i++) stSum+=v[i];
        ans=max(ans,stSum);
        ll reducedSum = 0;
        vector<ll> reducedV;
        for(ll i=1;i<v.size();i++) {
            reducedV.push_back(v[i]-v[i-1]);
            reducedSum+=(v[i]-v[i-1]);
        }
        ans=max(ans,abs(reducedSum));
        v=reducedV;
    }
    cout<<ans<<endl;
}
int main()
{
    DEATH_NOTE

    ll t;
    t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

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

using namespace std;
#define maxn 200002
#define int long long
#define ll long long

int init[50] = { 0, 1 };
int check(int n) {
    for (int i = 1; i < 50; ++i) {
        if (init[i] > n) return i - 2;
    }
    return 1;
}
void funToEnd(int l, int r, int tmp) {
    int rc = check(r);
    int a = 1 << rc ^ tmp;
    int b = ((1 << rc) - 1) ^ tmp;
    l = l ^ tmp;
    r = r ^ tmp;
    int c = 0;
    for (int i = l; i <= r; ++i) {
        if (i != a && i != b) {
            c = i;
            break;
        }
    }
//    int c = ((1 << rc) - 1) ^ tmp;
    cout << a << " " << b << " " << c << endl;
}

void loopSelf(int l, int r, int tmp) {
    int lc = check(l);
    int rc = check(r);
    if (lc != rc) {
        funToEnd(l, r, tmp);
        return;
    }
    int k = 1 << lc;
    loopSelf(l ^ k, r ^ k, tmp ^ k);
}

void solve() {
    int l = 0, r = 0;
    cin >> l >> r;
    loopSelf(l, r, 0);
}

signed main() {

    ios::sync_with_stdio(0);
    cin.tie(nullptr);
//    solve();
    for (int i = 2; i <= 31; ++i) {
        init[i] = init[i - 1] << 1;
    }
    int t; cin >> t;
    while (t--) solve();

}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
#define _11037_ ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define endl '\n'
#define int long long
#define MAX 100000 + 4
#define MOD 998244353

// int s[MAX];

signed main()
{
    _11037_

    int T, l, r;
    int i;

    cin >> T;

    while (T--)
    {
        cin >> l >> r;

        int a = 0, b = 0, c = 0;
        int mid, zero;

        mid = l ^ r;
        zero = 31 - __builtin_clz(l ^ r);

        a = (l | (1 << zero) - 1);
        b = a + 1;
        if (a == l)
            c = r;
        else
            c = l;

        cout << a << " " << b << " " << c;

        cout << endl;
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

using namespace std;

#define ll long long



int main(){

    ll t;

    cin>>t;

    while(t--){

        ll n,l,r;

        cin>>n>>l>>r;

        vector<ll> x(n);

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

        vector <ll> a,b,c;

        r--;

        l--;

        for(ll i=0;i<l;i++) a.push_back(x[i]);

        for(ll i=l;i<=r;i++) b.push_back(x[i]);

        for(ll i=r+1;i<n;i++) c.push_back(x[i]);

        ll z=r-l+1;

        if(a.size()) sort(a.begin(),a.end());

        if(b.size()) sort(b.rbegin(),b.rend());

        if(c.size()) sort(c.begin(),c.end());

        ll sum=0;

        for(ll i=l;i<=r;i++) sum+=x[i];

        ll ans=sum;

        vector<ll> sumb;

        sumb.push_back(b[0]);

        for(ll i=1;i<b.size();i++) sumb.push_back(sumb.back()+b[i]);

        if(a.size()){

            vector<ll> suma;

            suma.push_back(a[0]);

            for(ll i=1;i<a.size();i++) suma.push_back(suma.back()+a[i]);

            for(ll i=1;i<=min(z,(ll)a.size());i++){

                ll sum1=0;

                // for(ll j=0;j<i;j++) sum1+=a[j];

                sum1=suma[i-1];

                ll sum2=0;

                // for(ll j=b.size()-1;j>=b.size()-i;j--) sum2+=b[j];

                sum2=sumb[i-1];

                if(sum1<sum2) ans=min(ans,sum-sum2+sum1);

                else ans=min(ans,sum);

            }

        }

        if(c.size()){

            vector<ll> sumc;

            sumc.push_back(c[0]);

            for(ll i=1;i<c.size();i++) sumc.push_back(sumc.back()+c[i]);

            for(ll i=1;i<=min(z,(ll)c.size());i++){

                ll sum1=0;

                // for(ll j=0;j<i;j++) sum1+=c[j];

                sum1=sumc[i-1];

                ll sum2=0;

                // for(ll j=b.size()-1;j>=b.size()-i;j--) sum2+=b[j];

                sum2=sumb[i-1];

                if(sum1<sum2) ans=min(ans,sum-sum2+sum1);

                else ans=min(ans,sum);

            }

        }

        cout<<ans<<endl;

    }

    return 0;

}

Solution 2 (runtime: 187 ms):
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
void solve()
{
    int n,l,r;
    cin>>n>>l>>r;
    vector<ll>v,pre,post;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(i<l)pre.push_back(x);
        else if(i>r)post.push_back(x);
        else {
            pre.push_back(x);
            post.push_back(x);
        }
    }
    sort(all(pre));
    sort(all(post));
    int k=r-l+1;
    ll cnt=0,mn=1e18;
    for(int i=0;i<k;i++){
        cnt+=pre[i];
    }
    mn=min(mn,cnt);
    cnt=0;
    for(int i=0;i<k;i++){
        cnt+=post[i];
    }
    mn=min(mn,cnt);
    cout<<mn<<endl;
}
int main()
{
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
const int mod = 1000000007; 
const int N = 1e5+10; 
using namespace std;
typedef pair<int,int>pii;
#define endl "\n"
#define yes cout<<"YES\n"
#define no  cout<<"NO\n"
#define forn(i,x, n) for (int i = x; i < int(n); i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define stin(a) string a; cin>>a
#define sz(a) (int)(a.size())
#define fin(a) for (auto &x : a) cin>>x
#define fout(a) for (auto &x : a) cout<<x<<" "; cout<<endl;
#define ll long long int
ll powm(ll x, ll n) {
    x %= mod;
    if (n == 0)
        return 1;
    else if (n == 1)
        return x%mod;
    int p = powm(x * x%mod, n / 2);
    if (n % 2)
        return p * x % mod;
    else
        return p;
}
void solve()
{
    int n; cin>>n;
    vector<int>v(n); fin(v);
    
    for(int i=0;i<n-1;i++)
    {
      if(v[i]>v[i+1]) {
        no; return;
      }
      v[i+1]-=v[i];
    }
    yes;
}
int32_t main()
{
   ios_base::sync_with_stdio (0);
   cin.tie (0);
   cout.tie (0);
   int t; cin>>t; while(t--)
   solve();
}

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







/*
input n, k
genrate an array with n numbers 
so to find those min numbers?
we get n/2 min numbers
arrange these as 

if k == 1 print the 1 ........ n elemets  

if k > 1 

put n/2 element in the end of the kth position of the array 



*/









void pv(vector<vector<ll>> &subset){
    for (int i = 0; i<subset.size(); i++){
        for(int j = 0; j<subset[i].size(); j++)
            cout<<subset[i][j]<<" ";
        cout<<endl;
    }
    cout<<endl;
}

void print(vector<ll> &temp){
   for(int i = 0; i<temp.size(); i++)
        cout<<temp[i];

   cout<<endl;
}


void solve(){
    //  create a queue and push the element in sequence 
    // for each inserting element 

    unsigned int n;
    cin>>n;
    vector<ll> v(n);
    
    for(unsigned int i = 0; i<n; i++){
        cin >> v[i];
    }
    bool c = false;
    for(unsigned int i = 1; i<n; i++){
        if(v[i-1] > v[i]){
            c = true;
            break;
        }
        else{
            v[i] -= v[i-1];
            v[i-1] = 0;
        }
    }
    (c)?cout<<"NO\n":cout<<"YES\n";
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt; 
    cin >> tt;
    while (tt--)    
        solve();
    
    return 0;
}

/*
6
1 1 3 5
1 3 2 1
8 10 28 100
100 1 100 1
1 100 1 100
100 100 0 100 100
0 0 6 5
*
*/