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

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fileio          freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll              long long
#define vi              vector<ll>
#define pb              push_back
#define all(x)          x.begin(), x.end()
#define endl            '\n'

using namespace std;
ll MOD = 1e9 + 7;

void solve() {
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int best = s[i] - '0', pos = i;
        for (int j = i; j < min(i + 10, (int) s.size()); j++) {
            if (s[j] - '0' - (j - i) > best) {
                best = s[j] - '0' - (j - i);
                pos = j;
            }
        }
        while (pos > i) {
            swap(s[pos], s[pos - 1]);
            pos--;
        }
        s[i] = char(best + '0');
    }
    cout << s << endl;
}

int main() {
    fastio
#ifndef ONLINE_JUDGE
    fileio
#endif
    int t = 1;
    cin >> t;
    // int i = 1;
    while (t--) {
        // cout << i++ << ": ";
        solve();
    }
    return 0;
}


// 11555
//i = 0
// 11--5
// 33

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

int main()
{
    string s;
    int num;
    cin>>num;
    while(num--)
    {
        cin>>s;
        int swapped;
        do {
            swapped = 0;
            for (int i = 1; i < s.size(); i++) {
                if (s[i] > s[i - 1] + 1) {
                   
                    char temp = s[i - 1];
                    s[i - 1] = s[i] - 1;
                    s[i] = temp;
                    swapped = 1; 
                }
            }
        } while (swapped); 
        cout<<s<<endl;
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 46 ms):
//C:\Users\shambho\AppData\Roaming\Sublime Text\Packages\User
/*
	AUTHOR    : shambho_1001
								*/

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

void init_code_mode(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

bool canimakereq(int req, int two_cnt, int three_cnt){
	int temp = req;

	temp -= min(three_cnt * 6, (temp/6)*6);
	temp -= min(two_cnt * 2, temp);

	

	if(temp == 0) return true;
	return false;

}

void shambho_1001(){

	string str;cin>>str;
	int sum = 0;
	int two_cnt = 0;
	int three_cnt = 0;
	for(auto &ch : str){
		sum += (ch-'0');

		if(ch == '2') two_cnt++;
		if(ch == '3') three_cnt++;

	}

	if(sum % 9 == 0){
		cout<<"YES"<<endl; return;
	}

	int ihave = two_cnt * 2ll + three_cnt * 6ll;

	int req = 9 - (sum % 9);

	while(req<=ihave){

		if(req % 2 == 0 && canimakereq(req, two_cnt, three_cnt)){
			cout<<"YES"<<endl; return;
		}
		req += 9;
	}

	cout<<"NO"<<endl;


}

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

	init_code_mode();
	
	int t = 1;
	cin>>t;
	while(t--){
		shambho_1001();
	}	
	return 0;
}	

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

#include <unordered_set>



using namespace std;



int min (int a, int b) {return a<b ? a : b;}

int max (int a, int b) {return a>b ? a : b;}



int main () {

    int t;



    cin >> t;

    while (t--) {

        string n;

        cin >> n;

        int sum=0;

        int sum_two=0, sum_six=0;

        //cout << n;

        for (int i=n.length()-1; i>=0; i--) {

            int digit = n[i] - '0';

            //cout << digit << endl;

            sum += digit;

            if (digit==2) {sum_two++;}

            if (digit==3) {sum_six++;}

        }

        unordered_set<int> possible_remainders;

        //cout << sum_two << ' ' << sum_six << endl;



        for (int i=0; i<=min(sum_two, 9); i++) {

            for (int j=0; j<=min(sum_six, 9); j++) {

                //cout << i << ' ' << j << endl;

                int sum = 2*(i) + 6*(j);

                //cout << sum << endl;

                possible_remainders.insert(sum%9);

            }

        }



        

        int found=0;

        for (auto &x: possible_remainders) {

            //cout << x << endl;

            if (((sum%9)+x)%9==0) {

                //cout << x << ' ' << sum << endl;

                cout << "YES" << endl;

                found=1;

                break;

            }

        }

        if (!found) cout << "NO" << endl;

    }

}
Problem: 2049C - MEX Cycle
Language: c++17 

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

typedef long long ll;

#define MII map<int, int>

#define UMII unordered_map<int, int>

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define vi vector<int>

#define vvi vector<vi>

#define qi queue<int>

#define si stack<int>

#define rep(i, a, b) for(int i = a; i < b; i++)

using namespace std;



int main(){

    ios::sync_with_stdio(0);

    cin.tie(0);



    int t;

    cin >> t;

    while(t--){

        int n, x, y;

        cin >> n >> x >> y;

        if(x > y) swap(x, y);

        x--;

        y--;

        vector<int> arr(n);

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

            arr[(x+i) % n] = i % 2;

        }

        if((y - x) % 2 == 0 || (x+n-y) % 2 == 0) arr[x] = 2;



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

            cout << arr[i] << " ";

        }

        cout << endl;

    }

    return 0;

}

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



const int N = 200100;



int n, x, y;

int a[N];



int calc(std::vector<int> element) {

    for (int mex = 0;; mex ++) {

        bool flag = 0;

        for (int x : element)

            if (x == mex) {

                flag = 1;

                break;

            }

        

        if (!flag)

            return mex;

    }

}



void work() {

    std::cin >> n >> x >> y;



    a[x] = a[y] = -1;



    int state = 1;

    for (int i = x + 1; i <= y - 1; i ++)

        a[i] = (state ^= 1);

    

    state = 1;

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

        a[i] = (state ^= 1);

    for (int i = 1; i <= x - 1; i ++)

        a[i] = (state ^= 1);

    

    a[x] = calc({a[x == 1 ? n : x - 1], a[x == n ? 1 : x + 1]});

    a[y] = calc({a[y == 1 ? n : y - 1], a[y == n ? 1 : y + 1], a[x]});



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

        std::cout << a[i] << ' ';

    std::cout << '\n';

}



int main() {

    std::ios::sync_with_stdio(0);

    std::cin.tie(0);



    int T;

    std::cin >> T;



    while (T --)

        work();

    

    return 0;

}



/*

 *  心中无女人

 *  比赛自然神

 *  模板第一页

 *  忘掉心上人

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

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pll;
const int N=1e5+5;
void solved()
{
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++){
        int mx=s[i]-'0',k=i;
        for(int j=i+1;j<=i+10&&j<n;j++){
            int a=s[j]-'0';
            if(mx<a-j+i){
                k=j;mx=a-j+i;
            }
        }
        if(k!=i){
            for(int j=k;j>=i+1;j--)
                s[j]=s[j-1];
            s[i]=mx+'0';
        }
    }
    cout<<s<<"\n";
}   
int main()
{   
    ios::sync_with_stdio(false);    
    cin.tie(nullptr); 
    cout.tie(nullptr);
    //int t=1;
    int t;cin>>t;
    while(t--)
        solved();
    return 0;
}

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

#define all(x) (x).begin(), (x).end()

#define lli long long

#define llu unsigned long long

#define vi vector<int>

using namespace std;



void merge(vector<char>& a, int p, int q, int r) {

    int n1 = q - p + 1;

    int n2 = r - q;

    vector<char> left(n1);

    vector<char> right(n2);

    for (int i = 0; i < n1; i++) left[i] = a[p + i];

    for (int i = 0; i < n2; i++) right[i] = a[q + i + 1];

    int i = 0, j = 0, k = p;

    while (i < n1 && j < n2) {

        if (right[j] - (n1 + j - (k - p)) > left[i]) {

            a[k++] = right[j] - (n1 + j - (k - p));

            j += 1;

        } else {

            a[k++] = left[i];

            i += 1;

        }

    }

    while (i < n1) a[k++] = left[i++];

    while (j < n2) a[k++] = right[j++];

}



void merge_sort(vector<char>& a, int n) {

    int size = 1;

    while (size < n) {

        for (int l = 0; l < n - size; l += 2 * size) {

            merge(a, l, l + size - 1, min(l + 2 * size - 1, n - 1));

        }

        size += size;

    }

}



void solve() {

    string s;

    cin >> s;

    vector<char> a(all(s));

    merge_sort(a, s.size());

    for (auto& t : a) cout << t;

    cout << '\n';

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    int T;

    cin >> T;

    while (T--) {

        solve();

    }

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

Solution 1 (runtime: 62 ms):
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;
void ans(){
    int n; cin>>n;
    vector<ll>v(n);
    long long s=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
        s+=v[i];
    }
    if(n==1){
        cout<<s<<endl;
        return;
    }
    // s=s;
    
    for(int i=0;i<n;i++){
        long long sum=0;
        for(int j=0;j<n-i-1;j++){
           
            v[j]=v[j+1]-v[j];
             sum+=v[j];
            // cout<<v[j]<<" ";
        }
        // sum=abs(sum);
        // cout<<sum<<" ";
        // cout<<endl;
        s=max(s,abs(sum));
    }
    cout<<s<<endl;

}

int main(){
    int t;cin>>t;
    while(t--){
        ans();
    }
    return 0;
}

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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<ll> v;
        for(int i = 0; i < n; i++){
            int a;
            cin >> a;
            v.push_back(a);
        }
        if(n == 1){
            cout << v[0] << endl;
            continue;
        }
        ll ans = accumulate(v.begin(), v.end(), 0LL);
        vector<ll> u;
        while(n > 1){
            for(int i = 0; i < n - 1; i++)u.push_back(v[i + 1] - v[i]);
            ll sum = accumulate(u.begin(), u.end(), 0LL);
            for(int i = 0; i < n - 1; i++)v[i] = u[i];           
            u.clear();
            ans = max(ans, abs(sum));
            n--;
        }
        cout << ans << endl;
    }
}
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 1389 ms):
#include <bits/stdc++.h>
#define pii pair<int, int> 
#define lowbit(x) (x&-x) 
#define ll long long  
#define ull unsigned long long
#define endl "\n"
const int mod = 998244353;
const int inf = 1e9;
const ll llf = 1e18;
using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int i, j;
	int n, m;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int x;
		map<int, int>mymap;
		bool flag = 1;
		cin >> n >> m;
		while (n--)
		{
			cin >> x;
			mymap[x]--;
		}
		while (m--)
		{
			cin >> x;
			mymap[x]++;
		}
		for (auto it =mymap.rbegin();it != mymap.rend();)
		{
			if (it->first== 1)
			{
				if (it->second)
					flag = 0;
			}
			if (it->second < 0)
			{
				flag = 0;
				break;
			}
			mymap[it->first / 2] += it->second;
			mymap[it->first - it->first / 2] += it->second;
			mymap.erase(it->first);
		}
		int flag1 = 1;
		for (auto x : mymap)
		{
			if (x.second)
				flag1 = 0;
		}
		if (flag && flag1)
			cout << "YeS" << endl;
		else
			cout << "nO" << endl;
	}
}

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

#include<cstdio>

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/assoc_container.hpp>

#define no cout<<"NO\n";

#define yes cout<<"YES\n";

#define ll long long

using namespace std;

using namespace __gnu_pbds;

template<class T>

using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

//ll lcm(ll a,ll b){return (a/__gcd(a,b))*1LL*b;}

int main()

{

	ios_base::sync_with_stdio(NULL);

	cin.tie(0); cout.tie(0);

	//freopen("intern.in", "r", stdin);

	//freopen("flags.out", "w", stdout);

	int t;

	cin>>t;

	while(t--)

    {

        int n,m,x;

        cin>>n>>m;

        multiset<int>st1,st2;

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

            cin>>x,st1.insert(x);

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

            cin>>x,st2.insert(x);

        while(!st1.empty()&&!st2.empty()&&st2.size()<=st1.size())

        {

            auto it1=*st1.rbegin();

            auto it2=*st2.rbegin();

            st1.erase(st1.find(it1));

            st2.erase(st2.find(it2));

            if(it1==it2)continue;

            if(it1>it2)break;

            st1.insert(it1);

            st2.insert(it2/2);

            st2.insert(it2/2+it2%2);

        }

        if(st1.size()+st2.size())no

        else yes

    }

}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

void solve(){
    cin>>n;
    int a[n+5];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    bool f=1;

    
        for(int i=2;i<=n;i++){
            if(a[i]<a[i-1] ) {cout<<"NO"<<"\n";return;}
            a[i]-=a[i-1];
            a[i+1]-=a[i];
            a[i]=0;
        }
   
        cout<<"YES"<<'\n';
    
}
signed main(){
    
    int t;
    scanf("%lld",&t);
    while(t--) solve();
}

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

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

    int test_case = 1;
    cin >> test_case;

    while (test_case--) {
        int n;
        cin >> n;
        vector<int> v(n);

        for (int i = 0; i < n; i++)  cin >> v[i]; 
        if(is_sorted(v.begin(), v.end())) cout << "YES\n";
        else {
            bool ok = 1;
            for(int i = 0; i < n - 2;  ) {
                if(v[i] <= v[i + 1]) {
                    i += 2;
                }
                else {
                    ok = 0;
                    break;
                }
            }
            if(ok) cout << "YES\n";
            else cout << "NO\n";
        }
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
// dp solution 
int solve(int i, int j, int n, int m, string &s1, string &s2, string &s3, vector<vector<int>> &dp) {
    if (i + j == s3.length()) return 0; 
    if (dp[i][j] != -1) return dp[i][j]; 
    int ans = INT_MAX;
    if (i < n && s1[i] == s3[i + j]) {
        ans = min(ans, solve(i + 1, j, n, m, s1, s2, s3, dp));
    }
    if (j < m && s2[j] == s3[i + j]) {
        ans = min(ans, solve(i, j + 1, n, m, s1, s2, s3, dp));
    }
    if (i < n && s1[i] != s3[i + j]) {
        ans = min(ans, 1 + solve(i + 1, j, n, m, s1, s2, s3, dp));
    }
    if (j < m && s2[j] != s3[i + j]) {
        ans = min(ans, 1 + solve(i, j + 1, n, m, s1, s2, s3, dp));
    }

    return dp[i][j] = ans; 
}

//recursion 
int solve1(int i,int j,int k,string &s1,string &s2,string s3){
   if(i==s1.length() && j==s2.length())return 0;
   int ans=INT_MAX;
   if(i==s1.length()){
    ans=min(ans,((s3[k]!=s2[j])?1:0)+solve1(i,j+1,k+1,s1,s2,s3));
   }
   else if(j==s2.length()){
     ans=min(ans,((s3[k]!=s1[i])?1:0)+solve1(i+1,j,k+1,s1,s2,s3));
   }
   else{
    ans=min(ans,min(((s3[k]!=s2[j])?1:0)+solve1(i,j+1,k+1,s1,s2,s3),((s3[k]!=s1[i])?1:0)+solve1(i+1,j,k+1,s1,s2,s3)));
   }
   return ans;
}


int main() {
    int t;
    cin >> t;
    while (t--) {
        string s1, s2, s3;
        cin >> s1 >> s2 >> s3;

        int n = s1.length(), m = s2.length();
        vector<vector<int>> dp(n + 1, vector<int>(m + 1, -1)); 

        cout << solve(0, 0, n, m, s1, s2, s3, dp) << endl; 
    }
    return 0;
}


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

void solve(){

    string a,b,c;
    cin>>a>>b>>c;

    int l = a.size(), m = b.size(), n = c.size();
    vector<vector<int>> dp(l+2, vector<int>(n+2, INT_MAX));

    dp[0][0] = 0;
    for(int i=1, j=0; i<=n ; i++){
        if(i<=m && b[i-1]!=c[i-1])
            j++;
        dp[0][i] = j;
    }

    for(int i=1 ; i<=l ; i++){
        for(int j=i ; j<=i+m ; j++){
            
            int val = dp[i-1][j-1] + (a[i-1]!=c[j-1]?1:0);
            val = min(val, dp[i][j-1] + (b[j-i-1]!=c[j-1]?1:0));
            dp[i][j] = val;

        }
    }

    // for(int i=0;i<=l;i++){
    //     for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<dp[l][n]<<'\n';
    
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

using namespace std; 



void solve(){

    string s;

    cin>>s;

    

    int sum=0,c2=0,c3=0;

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

        sum+=(int)(s[i]-48);

        if(s[i]=='2') c2++;

        if(s[i]=='3') c3++;

    }



    if(sum%9==0){

        cout<<"YES"<<endl;

    }

    else{

        int x=9-sum%9;

        if(x==1 && (c2>=5 || (c2>=2 && c3>=1))){

            cout<<"YES"<<endl;

        }

        else if(x==2 && c2>=1){

            cout<<"YES"<<endl;

        }

        else if(x==3 && (c2>=6 || c3>=2 || (c2>=3 && c3>=1))){

            cout<<"YES"<<endl;

        }

        else if(x==4 && c2>=2){

            cout<<"YES"<<endl;

        }

        else if(x==5 && (c2>=7 || (c2>=1 && c3>=2) || (c2>=4 && c3>=1))){

            cout<<"YES"<<endl;

        }

        else if(x==6 && (c3>=1 || c2>=3)){

            cout<<"YES"<<endl;

        }

        else if(x==7 && (c2>=8 || (c2>=2 && c3>=2) || (c2>=5 && c3>=1))){

            cout<<"YES"<<endl;

        }

        else if(x==8 && (c2>=4 || (c2>=1 && c3>=1))){

            cout<<"YES"<<endl;

        }

        else{

            cout<<"NO"<<endl;

        }

    }

}



int main(){

    

    int t=1;

    cin>>t;



    while(t--){

        solve();

    }

return 0;

} 

Solution 2 (runtime: 62 ms):
#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;



#define int long long 

#define float long double

#define pb push_back

#define vi vector<int>

#define pii pair<int,int>

#define si set<int>

#define usi unordered_set<int>

#define msi multiset<int>

#define mii map<int,int>

#define umii unordered_map<int,int>

#define mp make_pair

#define ff first

#define ss second

#define vii vector<pii>

#define all(x) (x).begin(),(x).end()

#define MAX(x) *max_element(all(x))

#define MIN(x) *min_element(all(x))

#define SUM(x) accumulate(all(x),0ll)

#define rep(i,a,b) for(int i=(a);i<(b);i++)

#define bck(i,a,b) for(int i=(a)-1;i>=(b);i--)



typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key



const int MOD = 1e9 + 7;



int mod(int a, int m) {

    return (a % m + m) % m;

}



void solve() {

    



    string s;

    cin>>s;



    int sum = 0;

    int c2 = 0;

    int c3 = 0;



    rep(i,0,s.size()){

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

        if(s[i]=='2')c2++;

        if(s[i]=='3')c3++;

    }



    int l1 = min(8ll,c2);

    int l2 = min(2ll,c3);



    rep(i,0,l1+1){

        rep(j,0,l2+1){

            int k = sum+(2*i+6*j);

            if(k%9==0){

                cout<<"YES"<<endl;

                return;

            }

        }

    }



    cout<<"NO"<<endl;



    



}



int32_t main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    int t;

    cin >> t;



    while (t--) {

        solve();

    }



    return 0;

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

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

using namespace std;





/*

    1. long long ko int 

    2. divide by 0 (always take care)

    3. 1e9 me map 

    4. 1e5 me unordered map/set

*/

#define int long long

#define loop(i,a,b) for(int i=a;i<b;i++)

#define rloop(i,a,b) for(int i = a;i>=b; i--)

#define YES cout << "YES" << endl

#define NO cout << "NO" << endl

#define vin vector<int>

#define vvin vector<vector<int>>

#define pb push_back



void solve(){



    int n , l , r;

    cin >> n >> l >> r;



    l-- , r--;



    vin a(n);



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

        cin >> a[i];

    }



    vin leftarr;



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



        leftarr.push_back(a[i]);

    }



    vin rtarr;



    



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



        rtarr.push_back(a[i]);

       

    }



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

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



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

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



    cout << min(anslft , ansrt) << endl;



     

}





int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    int T;

    cin >> T;



    while (T--)

        solve();



    return 0;

}

Solution 2 (runtime: 202 ms):
#include<iostream>
#include<algorithm>
using namespace std;
bool descending(long long a, long long b) {
    return a > b;  // 返回true表示a排在b前面（降序）
}
long long  a[100005];
long long  b[100005];
long long  c[100005];
int main()
{
    int t;cin>>t;
    while(t--)
    {
        long long  n,l,r;
        cin>>n>>l>>r;
        l--,r--;
        for(long long i=0;i<n;i++)
        {
            cin>>a[i];
            b[i] = a[i];
            c[i] = a[i];
        }
        sort(b,b+r+1,descending);

        sort(c+l,c+n);

        long long   ans1 = 0;
        long long   ans2 = 0;
        for(long long i =l;i<=r ;i++)
        {
            ans1 += b[i];
            ans2 += c[i];
        }
        cout<<min(ans1,ans2)<<endl;
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

void solve() {
   int n; cin>>n;
   vector<int> a(n);
   for(int i = 0; i<n; i++){
      cin>>a[i];
   }  
   for(int i = 1; i<n; i++){
      int m = min(a[i], a[i-1]); 
      a[i] -= m; a[i-1] -= m;
   }
   if(is_sorted(a.begin(), a.end()))
      cout<<"Yes"<<'\n';
   else
      cout<<"No"<<'\n';
}

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

   int t; cin>>t;
   while(t--){
      solve();
   }
}

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

using namespace std;

#define int long long

signed main()

{

int t;cin>>t;

while(t--){

int n;cin>>n;

vector<int> a(n);

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

cin>>a[i];

}



bool check=0;

int mid;

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

mid=min(a[i],a[i+1]);

a[i]-=mid;

a[i+1]-=mid;

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

//        	if(i==0) cout<<endl;

//          cout<<a[i]<<" ";

//      }

}





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

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

{

cout<<"No"<<endl;

check=1;

break;

}

}



if(check==0){

cout<<"Yes"<<endl;

}



}



return 0;

}