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

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

#include<bits/stdc++.h>

#define int long long

using namespace std;

signed main(){

    cin.tie(0);

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        int l=s.length();

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

            int best=s[i];int pos=i;

            for(int j=i;j<min(i+10,(int)l);j++){

                if(s[j]-j+i>best){

                    best=s[j]-j+i;

                    pos=j;

                }

            }

            while(pos>i){

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

                pos--;

            }

            s[i]=(char)best;

        }

        cout<<s<<endl;

    }

}

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

#include <string.h>



using namespace std;

using vi = vector<int>;

using ll = long long;



void solve() {

    string s;

    cin >> s;

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

        int max = s[i] - '0', pos = i;

        for (int j = i; j < min(i+10, (int)s.size()); j++) {

            if (s[j] - '0' - (j-i) > max) {

                max = s[j] - '0' - (j-i);

                pos = j;

            }

        }

        while (pos > i) {

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

            pos--;

        }

        s[i] = char(max + '0');

    }

    cout << s << endl;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int t;

    cin >> t;

    while (t--) solve();

}



/*

    int n, m;

    cin >> n >> m;

    int sum = 0;

    int count = 0;

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

        string s;

        cin >> s;

        sum += s.size();

        if (sum <= m)

            count++;

    }

    cout << count << endl;



*/
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 187 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>num(n);

        vector<int>ls(n);

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

            cin>>num[i];

            ls[i]=num[i];

        }

        sort(num.begin(),num.begin()+r);

        long long ans1=0,ans2=0;

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

            ans1+=num[i];

        }

        sort(ls.begin()+l-1,ls.end());

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

            ans2+=ls[i];

        }

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

    }

    system("pause");

    return 0;

}

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

using namespace std;



typedef long long ll;

typedef pair<int, int> ii;

typedef vector<int> vi;

typedef vector<ii> vii;



#define ALL(x) begin(x), end(x)



int main() {

    int T; cin >> T;

    while (T--) {

    int n, l, r;

    cin >> n >> l >> r;

    l--, r--;

    vi a(n);

    for (int &x : a) cin >> x;

    ll sum_l_r = 0;

    for (int i = l; i <= r; i++) sum_l_r += a[i];

    

    vi in_front, in_between, after;

    for (int i = 0; i < l; i++) in_front.push_back(a[i]);

    for (int i = l; i <= r; i++) in_between.push_back(a[i]);

    for (int i = r+1; i < n; i++) after.push_back(a[i]);



    sort(ALL(in_front));

    sort(ALL(in_between));

    reverse(ALL(in_between));

    sort(ALL(after));



    ll sum_swap_front = sum_l_r;

    for (int i = 0; i < in_front.size() && i < in_between.size() && in_front[i] < in_between[i]; i++) {

        sum_swap_front -= in_between[i]-in_front[i];

    }



    ll sum_swap_back = sum_l_r;

    for (int i = 0; i < after.size() && i < in_between.size() && after[i] < in_between[i]; i++) {

        sum_swap_back -= in_between[i]-after[i];

    }



    cout << min(sum_swap_front, sum_swap_back) << '\n';

}

}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 1156 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
ll mod=1e9+7;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 ll n;
 cin>>n;
 vector<ll>final(n+1);unordered_map<ll,ll>mp;
 for(ll i=1;i<=n;i++) cin>>final[i];
 for(ll i=1;i<=n;i++)
 {
    mp[final[i]]=i;
 }
 vector<pair<ll,ll>>ans;
 for(ll i=1;i<=n-1;i++)
 {
    for(ll j=i+1;j<=n;j++) ans.push_back({j,i});
 }
 vector<ll>crr(n+1);
 for(ll i=n;i>=1;i--) crr[i]=n-i+1;
 while(true)
 { bool flag=false;
    for(ll i=1;i<=n-1;i++)
    {
        ll a=crr[i]; ll b=crr[i+1];
if((b<a && mp[a]>mp[b]) ) {flag=true; swap(crr[i],crr[i+1]); ans.push_back({b,a});}
    }
    if(!flag) break;
 }
 cout<<ans.size()<<endl;
 
 for(auto &it:ans) cout<<it.first<<" "<<it.second<<endl;


}

Solution 2 (runtime: 1155 ms):
#pragma GCC optimize("Ofast")
#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;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef unsigned long long ull;
#define V vector
#define pb push_back
#define pf push_front
#define qb pop_back
#define qf pop_front
#define eb emplace_back
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
#define fi first
#define se second
#define FR(i, a, b) for (int i = a; i <= b; i++)
#define FRR(i, a, b) for (int i = a; i >= b; i--)
#define _sort(x) sort((x).begin(),(x).end());
const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const ll infl = 0x3f3f3f3f3f3f3f3fll;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t;
    t=1;
    while(t--){
        int n;
        cin>>n;
        V<int>arr(n);
        for(auto &x:arr)cin>>x;
        V<pii>res;
        V<int>b(n);
        for(int i=1;i<=n;i++){
            b[i-1]=n-i+1;
        }
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                res.push_back({j,i});
            }
        }
        int i=n-1;
        while(i>=0){
            while(b[i]==arr[i]&&i>=0){
                i--;
            }
            if(i<0)break;
            int j=0;
            while(j<i){
                if(b[j]==arr[i]){
                    j++;
                    break;
                }
                j++;
            }
            while(j<=i){
                b[j-1]=b[j];
                res.push_back({b[j],arr[i]});
                j++;
            }
            b[i]=arr[i];
    
        }
        cout<<res.size()<<endl;
        for(auto it:res){
            cout<<it.fi<<" "<<it.se<<endl;
        }
    }
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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

void init_code() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

void solve() {
	int n, k;
	int res = 0;

	cin >> n >> k;

	vector<int> a(n);

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

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

	vector<int> frequency = {1};
	for (int i = 1; i<n; i++) {
		if (a[i] == a[i-1]) frequency.back()++;
		else frequency.emplace_back(1);
	}

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

	int unique = frequency.size();
	for (int i = 0; i<frequency.size(); i++) {
		if (frequency[i] > k) {
			cout << unique - i << endl;
			return;
		}
		k -= frequency[i];
	}

	cout << 1 << endl;
}

int main() {
	init_code();

	int t;
	cin >> t;

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

	return 0;
}

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

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

    while (t--) {
        int n, k, temp;
        cin >> n >> k;

        map<int, int> m;
        for (int i = 0; i < n; i++) {
            cin >> temp;
            m[temp]++;
        }

        vector<int> v;
        for (auto x : m) {
            v.push_back(x.second);
        }

        sort(v.begin(), v.end());
        int ans = v.size();

        if (k == 0) {
            cout << ans << endl;
            continue;
        }

        for (int i = 0; i < v.size(); i++) {
            k -= v[i];
            if (k < 0) {
                break;
            }
            ans--;
        }
        cout << max(ans, 1) << endl;
    }

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

Solution 1 (runtime: 78 ms):
// https://codeforces.com/problemset/problem/2050/D

#include <iostream>
#include <string>

int main() {
  int n;
  std::string x;

  std::cin >> n;

  while (n-- > 0) {
    std::cin >> x;
    for (int i = 1; i < x.size(); i++) {
      for (int j = i; j > 0; j--) {
        if (x[j] - 1 > x[j-1]) {
          std::swap(x[j], x[j-1]);
          x[j-1]--;
        } else {
          break;
        }
      }
    }
    std::cout << x << std::endl;
  }
}

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



using namespace std;



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;

}



int main() {

    int TESTS = 1; cin >> TESTS;

    while (TESTS --> 0) {

        solve();

        cout << '\n';

    }

    return 0;

}
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

int main()
{
    int n;
    cin>>n;
    int c[n+1], d[n+1];
    for(int i=1;i<=n;i++){
    cin>>d[i];
    c[d[i]]=i;
    }
    
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(c[i]<c[j]) ans++;
            ans++;
        }
    }
    cout<<ans<<endl;
    for(int i=2;i<=n;i++)
    {
        for(int j=n;j>=1;j--)
        {
            if(d[j]<i) cout<<i<<" "<<d[j]<<endl;
        }
        for(int j=1;j<=n;j++)
        {
            if(d[j]<i && j<c[i]) cout<<d[j]<<" "<<i<<endl;
        }
    }
return 0;
}

Solution 2 (runtime: 296 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int MAXN = 1e3+5;
ll a[MAXN], b[MAXN];
void solve()
{
    ll n;
    vector<pair<ll, ll>> ans;
    cin >> n;
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = i;
    }
    for (ll i = n; i >= 1; i--) {
        ll k;
        for (ll j = 1; j <= i; j++) {
            if (a[i] == b[j]) {
                k = j;
                break;
            }
        }

        while (k > 1) {
            ans.push_back({b[k], b[k-1]});
            swap(b[k], b[k-1]);
            k--;
        }

        for (ll j = 1; j < i; j++) {
            ans.push_back({b[j+1], b[j]});
            swap(b[j], b[j+1]);
        }
    }
    cout << ans.size() << '\n';
    for (auto i : ans) {
        cout << i.first << ' ' << i.second << '\n';
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    // cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
 
void solve() {
	int l,r;
    cin>>l>>r;
	int c=31-__builtin_clz(l^r);
	int a=l|((1<<c)-1),b=a+1;c=(a==l?r:l);
	cout<<a<<" "<<b<<" "<<c<<endl;
}
 
signed main() {
    int t ;
    cin >> t;
 
    while (t--) {
        solve();
    }
}

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
void solve(){
    int l,r;
    cin>>l>>r;
    int diff=31- __builtin_clz(l^r);
    int a=l|((1<<diff)-1);
    int b=a+1;
    int c=(a==l?r:l);
    cout<<a<<" "<<b<<" "<<c<<endl;
    
}
int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=2*(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
ll mn, n,t, cm, b, sat, c, l, r, k, m;
ll a[dim], res[dim], cnt[dim];
pll p[dim];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n;

        for(int i=1; i<=n; i++){
            cin>>a[i];
        }
        ll fl=0;
        for(int i=1; i<n; i++){
            if(a[i]>a[i+1]){
                fl=1;
            }
            else{
                a[i+1]-=a[i];
            }
        }
        if(fl==1){
            cout<<"NO"<<endl;

        }
        else cout<<"YES"<<endl;
    }


    return 0;
}


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

#define int long long 

using namespace std;

const int N = 2 * 1e5 + 10;

int n;
int a[N];
int t;

signed main() {
    cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 1;i <= n;++i) {
            cin >> a[i];
        }
        for (int i = 2;i <= n;++i) {
            int t = min(a[i - 1],a[i]);
            a[i - 1] -= t;
            a[i] -= t;
        }
        bool flg = false;
        for (int i = 2;i <= n;++i) {
            if (a[i] < a[i - 1]) {
                cout << "NO\n";
                flg = true;
            }
            if (flg) break;
        }
        if (flg) continue;
        cout << "Yes\n";
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 562 ms):
#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define vpl vector<pair<ll, ll>>
#define vpi vector<pair<int, int>>
#define pl pair<ll, ll>
#define M (int)(998244353)
#define N (int)(2 * 1e5 + 10)
#define eps 1e6
using namespace std;

void dfs(ll v, vector<ll> graph[],vector<ll> parent, vector<ll> &visited)
{
    if (visited[v])
    {
        return;
    }
    visited[v] = 1;

    for (auto &i : graph[v])
    {
        parent[v]++;
        dfs(i, graph, parent, visited);
    }
}

void solve()
{
    ll n;
    cin >> n;
    vector<ll> graph[n + 1];
    vector<ll> parent(n+1,0),visited(n+1,0);

    for (int i = 1; i <= n-1; i++)
    {
        ll u, v;
        cin >> u >> v;

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    ll ans = 0;
    ll mx = -1;
    ll mxi[2] = {-1,-1};
    ll size[n+1];
    // cout<<ans<<endl;

    for (int i = 1; i <= n; i++)
    {   
        size[i]=graph[i].size();
        if (mx <= graph[i].size())
        {
            mxi[0] = i;
            mx = graph[i].size();
        }
    }

    ll cnt=0;


 for (int i = 1; i <= n; i++)
    {
        if (mx == graph[i].size())
        {
           cnt++;
        }
    }

    if(cnt<=2){

   
   size[mxi[0]]=0;
    for (auto &i: graph[mxi[0]])
    {   
        size[i]-=1;
    }
    ans=mx;
    mx=-1;

    for (int i = 1; i <= n; i++)
    {   
       mx=max(size[i],mx);
    }
    // cout<<mxi[1]<<mx<<endl;

    ans+=mx-1;
   
    }

    else ans=2*mx-1;
    cout<<ans<<endl;

}

int main()
{

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

Solution 2 (runtime: 937 ms):
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
using namespace std;
typedef vector<int> vi;
const int N = 2e5+5, M = 1e9+7, INF = 1e18;

void solve() {
    int n; cin >> n;
    vi adj[n+1];
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    multiset<int> st;
    for (int i = 1; i <= n; i++) st.insert(adj[i].size());
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (auto &j : adj[i]) {
            int mx = adj[i].size() + adj[j].size() - 2;
            ans = max(ans, mx);
            st.erase(st.find(adj[j].size()));
        }
        st.erase(st.find(adj[i].size()));
        if (!st.empty()) {
            int mx = adj[i].size() + *st.rbegin() - 1;
            ans = max(ans, mx);
        }
        for(auto &j : adj[i]){
            st.insert(adj[j].size());
        }
        st.insert(adj[i].size());
    }
    cout << ans << '\n';
}
 
signed main() {
    // freopen("hps.in", "r", stdin);   
    // freopen("hps.out", "w", stdout);
    cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);
    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }
}
Problem: 2049B - pspspsps
Language: c++17 

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

using namespace std;

#define ll long long

#define pair pair<ll,ll>

ll n,m,say1,say2,cem=0;

int main()

{

    cin>>n;

    string s;

    while(n--)

    {

      cin>>m;

      cin>>s;

      say1=0;

      say2=0;

      bool b=0,b1=0;

      if(s[0]=='s')

      {

        s[0]='.';

      }

      if(s[m-1]=='p')

      s[m-1]='.';

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

      {

        if(s[i]=='p')

        b=1;

        if(s[i]=='s')

        b1=1;

      }

      if(b1 and b)

      cout<<"no"<<endl;

      else cout<<"yes"<<endl;

    }

}

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

#include<math.h>

#define ll long long

#define ld long double

using namespace std;

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

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

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

#define mod   1000000007

#define Exp   1e18

#define new   cout<<endl





ll gcd(ll m,ll n)

{

    ll l=max(m,n);

    ll k=min(m,n);

    ll r;

    while(k>0)

    {

        r=l%k;

        l=k;

        k=r;

    }

    return l;

}







void solve()

{

    ll n;cin>>n;

    string s;cin>>s;

    ll cnt=0,ss=0,pp=0,si=0,pi=-1;

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

    {

        if(s[i]=='s')

        {

            ss++;

            si=i;

        }

        if(s[i]=='p')

        {

            pp++;

            if(pi==-1)

            {

                pi=i;

            }

        }



    }

    if(ss==0||pp==0)

    {

        hmm;

        return;

    }

    if(si==0 || pi==n-1)

    {

        hmm;

        return;

    }

    na;





}





int main()

{

    ll t;

    t=1;

    cin>>t;

    while(t--)

    {



        solve();



    }



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

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

int main (){
   int t;
   cin>>t;
   while(t--){
    int n,k;
    cin>>n>>k;
    vector<int>arr(n,0);
    for(int i=0;i<n;i++) cin>>arr[i];
    map<int,int>mp;
    for(int i=0;i<n;i++) mp[arr[i]]++;
    vector<int>arr1;
    for(auto it:mp){
        arr1.push_back(it.second);
    }
    sort(arr1.begin(),arr1.end());
    int ele = 0;
    for(int i=0;i<arr1.size();i++){
        if(arr1[i]<=k) ele++;
        k = k - arr1[i];
    }
    if(arr1.size()==ele) cout<<1<<endl;
    else cout<<(arr1.size()-ele)<<endl;
    

   }

   
    return 0;
}

Solution 2 (runtime: 124 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t;cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		map<int,int> mp;
		for(int i=0;i<n;i++){
			int x;cin>>x;
			mp[x]++;
		}
		vector<int> v;
		for(auto i=mp.begin();i!=mp.end();i++){
			v.push_back(i->second);
		}
		sort(v.begin(),v.end());
		int ans=v.size();
		for(int i=0;i<v.size();i++){
			if(k>=v[i]) {
				ans--;
				k-=v[i];
			}
			else break;
		
		}
		if(!ans) ans++;
		cout<<ans<<'\n';
	} 
	return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
int n,l,r,a[100'005];
void solution(){
    cin>>n>>l>>r;
    for(int i=1;i<=n;i++) cin>>a[i];
    long long sum=accumulate(a+l,a+r+1,0ll);
    vector<long long> v,vl(1),vr(1);
    for(int i=1;i<=l-1;i++) vl.push_back(a[i]);
    for(int i=l;i<=r;i++) v.push_back(a[i]);
    for(int i=r+1;i<=n;i++) vr.push_back(a[i]);
    sort(vl.begin(),vl.end());
    sort(v.begin(),v.end(),greater<long long>());
    sort(vr.begin(),vr.end());
    v.insert(v.begin(),0ll);
    for(int i=1;i<=l-1;i++) vl[i]+=vl[i-1];
    for(int i=1;i<=r-l+1;i++) v[i]+=v[i-1];
    for(int i=1;i<=n-r;i++) vr[i]+=vr[i-1];
    long long ans=sum;
    for(int i=1;i<=r-l+1;i++){
        if(vl.size()>=i+1) ans=min(ans,sum-v[i]+vl[i]);
        if(vr.size()>=i+1) ans=min(ans,sum-v[i]+vr[i]);
    }
    cout<<ans<<'\n';
}
int T;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>T;
    while(T--) solution();
    return 0;
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
#define fast                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(nullptr);
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int a[N],b[N];
void solve()
{
    int n,l,r;
    cin>>n>>l>>r;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a,a+r);
    sort(b+l-1,b+n);
    ll ans=0,ans2=0;
    for(int i=0;i<=(r-l);i++) ans+=a[i];
    for(int i=l-1;i<=r-1;i++) ans2+=b[i];
    ll rst=min(ans,ans2);
    cout<<rst<<'\n';
}
int main()
{
    fast;
    int _ = 1;
    cin >> _;
    while (_--)
        solve();
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
 
using namespace std;
#define int long long
const int N=1e6+5;
#define endl '\n'
#define debug(x) cout<<#x<<" "<<x<<endl;
#define inf LLONG_MAX
#define pb(x) push_back(x)
#define all(x) (x).begin(),(x).end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

            
signed main(){
		fast

          int tc;
          cin >>tc;
          
          while(tc--){
            int n,ans=0,cnt=0,sum=0,x=0,y=0,z=0;
            cin>>n;
                    
            vector<int>vec;
            for(int i=0;i<n;i++){
                    cin>>x;
                    ans+=x;
                    vec.pb(x);
                }
            //ans=max(ans,sum);    

            if(vec.size()==1){
                cout<<ans<<endl;
                
            }    
            else{

                while(vec.size()>1){ 
                sum=0;vector<int>v;
                for (int i = 1; i <vec.size(); i++)
                {
                    //vec[i]-=vec[i-1];
                    v.pb(vec[i]-vec[i-1]);
                    sum+=(vec[i]-vec[i-1]);
                }
                //vec=v;
                ans=max(ans,sum);

                reverse(all(vec));
                sum=0;
                for (int i = 1; i <vec.size(); i++)
                {
                    //vec[i]-=vec[i-1];
                    //v.pb(vec[i]);
                    sum+=(vec[i]-vec[i-1]);
                }
                ans=max(ans,sum);
                vec=v;
                


                }
                cout<<ans<<endl;
                
                
                
            }

          }
          
 
}

Solution 2 (runtime: 61 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
    int n;
    cin >> n;

    vector<ll> nums(n);
    for (auto& a : nums)
        cin >> a;

    ll sum = LLONG_MIN;

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

        for (int j = 0; j < n - i; ++j)
        {
            runningsum += nums[j];
        }
        if (i == 0)
            sum = max(sum, runningsum);
        else
            sum = max(sum, max(runningsum, -runningsum));

        for (int j = 0; j < n - i - 1; ++j)
        {
            nums[j] = nums[j + 1] - nums[j];
        }
    }

    cout << sum << '\n';
}
return 0;
}