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

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

using namespace std;


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

    int T;
    cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        for(int i=0; i<(int)s.size(); i++)
        {
            for(int j=9; j>=0; j--)
            {
                bool flag = 0;
                for(int k=0; k<=9&&i+k<(int)s.size(); k++)
                {
                    int t = s[i+k]-'0';
                    if(t-k==j)
                    {
                        for(int l = i+k-1; l>=i; l--)
                        {
                            s[l+1] = s[l];
                        }
                        s[i] = j+'0';
                        flag = 1;
                        break;
                    }
                }
                if(flag) break;
            }
        }
        cout<<s<<"\n";
    }




    return 0;
}

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

#include <cstring>

using namespace std;

const int N = 2e5 + 5;



int t,m,n;

char s[N];



int main(){

	cin >> t;

	while(t --){

		cin >> s;

		for(int i = 0; s[i] != '\0'; i ++){

			int max_num = s[i] - '0', max_index = i;

			for(int j = i + 1; j < i + 9 && s[j] != '\0'; j ++){

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

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

					max_index = j;

				}

			}

			for(int j = max_index; j > i; j --) s[j] = s[j - 1];

			s[i] = max_num + '0';

		}

		cout << s << endl;

		

	}

	return 0;

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

Solution 1 (runtime: 61 ms):
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
 
int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
 
    while(t--){
        string x;
        cin>>x;
 
        int r=0, pos=0;
 
        for(int i=0 ; i<x.size() ; i++){
            r=x[i]-'0'; pos=i;
            for(int j=i ; j<min((int)x.size(),i+9) ; j++){
                if(x[j]-'0'-(j-i)>r){
                    r=x[j]-'0'-(j-i);
                    pos=j;
                }
            }
 
            while(pos>i){
                swap(x[pos], x[pos-1]);
                pos--;
            }
 
            x[i]=r+'0';
 
        }
 
        cout<<x<<"\n";
    }
    
    
    return 0;
}

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

using namespace std;

inline int f(char ch) {

    return ch - '0';

}

int main() {

    int tt;

    cin >> tt;

    while(tt--) {

        string s;

        cin >> s;

        int n = s.size();

        int r = n - 1;

        while(r > 0) {

            if(f(s[r]) - 1 > f(s[r - 1])) {

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

                s[r - 1]--;

                int l = r;

                while(l < n - 1 && f(s[l]) < f(s[l + 1]) - 1) {

                    swap(s[l], s[l + 1]);

                    s[l]--;

                    l++;

                }

            }

            r--;

        }

        cout << s << endl;

    }

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

Solution 1 (runtime: 108 ms):
#include <iostream>
#include <string>
using namespace std;
using ll = long long;

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

    while (t--) {
        
        string s;
        cin >> s;
        ll n = s.size();
        for (ll i = 0; i < n; i++) {
            ll maxc = s[i] - '0';
            ll maxi = i;
            for (ll j = i ; j < min(i+10,n); j++) {
                if (s[j] - '0' + (i - j) > maxc) {
                    maxc = s[j] - '0' + (i - j);
                    maxi = j;
                }
            }ll k = maxi;

            while(maxi > i) {
                swap(s[maxi], s[maxi - 1]);
                maxi--;
            }
            s[i] += (i - k);
        }

        cout <<s << endl;
    }

    return 0;
}


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

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

    while(t--){
        string s;
        cin>>s;
        int n=s.length();
        for(int i=0;i<n-1;i++){
            bool f=0;
            for(int j=1;j<n;j++){

                if(s[j]-1>s[j-1]){
                    f=1;
                    char t=s[j];
                    s[j]=s[j-1];
                    s[j-1]=t;
                    s[j-1]--;
                }
            }
            if(!f)break;
        }
        cout<<s<<endl;
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

using namespace std;

#define ll long long

#define pi pair<int, int>

#define pll pair<ll, ll>

#define vi vector <int>

#define vll vector <ll>

#define vpi vector<pair<int, int>>

#define vpll vector<pair<ll, ll>>

#define vvi vector<vector<int>>

#define vvll vector<vector<ll>>

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

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

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

#define f(start, end) for(ll i = (start); i < (end); i++)

    

bool odd(ll num) {return ((num & 1) == 1);}

bool even(ll num) {return ((num & 1) == 0);}

    

void solve() {

    ll n, l, r; cin >> n >> l >> r;

    l--, r--; // make it 0-based

    vll a(n), b, c;

    f(0, n) { cin >> a[i]; }

    f(0, r+1) {

        c.push_back(a[i]);

    }

    f(l, n) {

        b.push_back(a[i]);

    }

    sort(all(b)); sort(all(c));

    ll window = r-l+1;

    ll ans = accumulate(b.begin(), b.begin() + window, 0LL);

    ans = min(ans, accumulate(c.begin(), c.begin() + window, 0LL));

    cout << ans << endl;

}

    

int main() {

    ll t; cin >> t;

    while(t--) {

        solve();

    }

}

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

using namespace std;

typedef long long ll;

ll b[100005],c[100005];

void solve()

{

    ll n,l,r;cin>>n>>l>>r;

    vector<int> a(n+1);

    memset(b,0,sizeof(b));

    memset(c,0,sizeof(c));

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

    {

        cin>>a[i];

    }

    for(int i=1;i<=r;i++) b[i]=a[i];

    for(int i=l;i<=n;i++) c[i-l+1]=a[i];

    sort(b+1,b+1+r);

    ll s1=0,s2=0;

    for(int i=1;i<=r-l+1;i++) s1+=b[i];

    sort(c+1,c+n-l+2);

    for(int i=1;i<=r-l+1;i++) s2+=c[i];

    cout<<min(s1,s2)<<"\n";

}

signed main()

{

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	int T;

	cin>>T;

	while(T--)

	{

	    solve();

	}

	return 0;

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

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int, int> mii;
typedef map<int, char> mic;
typedef map<char, int> mci;

#define f(i, l, h) for(int i = l; i < h; i++)
#define cf(i, l, h) for(int i = l; i <= h; i++)
#define rf(i, h, l) for(int i = h - 1; i >= l; i--)
#define pb push_back

void solution() {
	int n, l, r;
	cin >> n >> l >>r;
	vll b, c;
	f(i, 0, n) {
		int a; cin >> a;

		if(i < r) b.pb(a);
		if(i >= l-1) c.pb(a);
	}

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

	ll ans1 = 0, ans2 = 0;
	f(i, 0, r-l+1){
		ans1 += b[i];
		ans2 += c[i];
	}

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

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

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

using namespace std;

const int N = 100005;

int a[N];

void solve(){

	int n,l,r;

	cin >> n >> l >> r;

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

		cin >> a[i];

	sort(a + l,a + 1 + r,greater<int>());

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

	long long ans1 = 0,ans2 = 0;

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

		int p = i - l + 1;

		if(p < l && a[p] < a[i])ans1 += a[p];

		else ans1 += a[i];

		int q = r + i - l + 1;

		if(q <= n && a[q] < a[i])ans2 += a[q];

		else ans2 += a[i];

	}

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

}

int main(){

	cin.tie(0);

	ios::sync_with_stdio(0);

	int T;cin >> T;

	while(T--)solve();

	return 0;

}
Problem: 2061D - Kevin and Numbers
Language: c++17 

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

#define int long long
    signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); 

int t;
cin>>t;
while(t--){
    int n,m;
    cin>>n>>m;
   
    map<int,int> mp1,mp2;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        mp1[x]++;
    }
    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        mp2[x]++;
       
    }
   
    bool ans=true;
    auto it=mp2.end();
    
    int count=n-m;
    while(count){
        it=mp2.end();
        if(mp2.empty()){
            break;
        }
        it--;
        
        int val=it->first;
        if(val==1||mp2.empty()){
            break;
        }
        if(mp1.find(val)==mp1.end()){
            count--;
            
            int fr=mp2[val];
            
            if(val%2){
                
              mp2[val/2]+=fr;
              mp2[(val+1)/2]+=fr;
            }
            else{
                
                fr=fr+fr;
                
                val/=2;
            //    cout<<val<<endl;
            //     cout<<fr<<endl;
                mp2[val]+=fr;
            }
            mp2.erase(it);
        }
        else{
            if(mp1[val]==mp2[val]){
                mp1.erase(val);
                mp2.erase(val);
            }
            else if(mp1[val]>mp2[val]){
                mp1[val]-=mp2[val];
                mp2.erase(val);
            }
            else{
                mp2[val]-=mp1[val];
                mp1.erase(val);
            }
        }
        
      
    }
    //  cout<<mp1.size()<<" "<<mp2.size()<<endl;
      if(mp1==mp2){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
   

}
}

Solution 2 (runtime: 186 ms):
//BHAI STALKINGggggg... HMMMMM
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define max3(a,b,c) max(max(a,b),c)
#define max4(a,b,c,d) max(max(a,b),max(c,d))
ll mod = 1000000007;

//Code Starts Here
void solve(){
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n),b(m);
    priority_queue<ll> pq;
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    for(ll i=0;i<m;i++){
        cin>>b[i];
        pq.push(b[i]);
    }
    sort(a.begin(),a.end());
    ll i = n-1;
    ll cnt = 0;
    while(!pq.empty() && i>=0 && cnt <= n-m){
        ll x= pq.top();
        pq.pop();
        if(a[i] == x){
            i--;
        }
        else{
            ll u = x/2;
            ll v = x-u;
            pq.push(u);
            pq.push(v);
            cnt++;
        }
        
    }
    if(i>=0 || !pq.empty()){
        cout<<"No\n";
    }
    else{
        cout<<"Yes\n";
    }
}

int main()
{
    fastio;
    ll t=1;
    cin>>t;
    while(t--)
    {
        solve();
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 77 ms):
#pragma GCC optimize(3,"Ofast","inline")

#include<bits/stdc++.h>

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

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

#define se second 

#define fi first

#define endl '\n'

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

#define pii pair<int,int>

#define pli pair<LL,int>

#define MEM(a,x) memset(a,x,sizeof(a))

#define lowbit(x) ((x)&-(x))

inline int Ls(int p){return p<<1;}

inline int Rs(int p){return p<<1|1;}

typedef long long LL;

typedef unsigned long long ULL;

using namespace std;

const int N=1e5+10,M=2*N;

int a[N];

LL ddo(int l,int r,int len)

{

    LL ans=0;

    vector<int>vc;

    rep(i,l,r+1) vc.emplace_back(a[i]);

    sort(all(vc));

    rep(i,0,len) ans+=vc[i];

    return ans;

}

inline void Solve()

{

    LL ans=1e18;

    int n,l,r;

    cin>>n>>l>>r;

    rep(i,1,n+1) cin>>a[i];

    //[1,r]

    ans=min(ans,ddo(1,r,r-l+1));

    //[l,n]

    ans=min(ans,ddo(l,n,r-l+1));

    cout<<ans<<endl;

}

int main()

{

    #ifndef ONLINE_JUDGE

        freopen("test_0.in","r",stdin);

        freopen("test_0.out","w",stdout);

    #endif

    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int _=1;

    cin>>_;

    while(_--){

        Solve();

    }

    return 0;

}



Solution 2 (runtime: 93 ms):
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

const int N=1e5+5;
int a[N],b[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int  t;cin>>t;
	while(t--){
		int n,l,r;
		cin>>n>>l>>r;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			b[i]=a[i];
		}
		sort(a+1,a+1+r);
		sort(b+l,b+n+1);
		ll sum1=0,sum2=0;
		for(int i=1;i<=r-l+1;i++)sum1+=a[i];
		for(int i=l;i<=r;i++)sum2+=b[i];
		cout<<min(sum1,sum2)<<"\n";
	}
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
// https://codeforces.com/problemset/problem/2062/C

#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>

int main() {
  constexpr auto MAX_SIZE = 50;
  int t;
  std::cin >> t;
  std::vector<long long> lst(MAX_SIZE);
  
  while (t-- > 0) {
    int n;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
      std::cin >> lst[i];
    }
    auto beg = lst.begin();
    auto max_sum = std::accumulate(beg, beg + n, 0LL);
    while(n-->1){
      for(int i = 0; i < n; ++i){
        lst[i] -= lst[i+1];
      }
      auto sum = std::abs(std::accumulate(beg, beg + n, 0LL));
      if (sum > max_sum) max_sum = sum;
    }
    std::cout << max_sum << "\n";
  }
  return 0;
}


Solution 2 (runtime: 62 ms):
#include <iostream>
#include<climits>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#define int long long
using namespace std;
const int maxn=200005;
int n;
int a[55];
int sum() {
    int s=0;
    for(int i=0;i<n;i++) {
        s+=a[i];
    }
    return s;
}
void small() {
    for(int i=0;i<n-1;i++) {
        a[i]=a[i+1]-a[i];
    }
    n--;
}
void solve() {
    cin>>n;

    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    int mx=sum();
    while(n>1) {
        small();
        mx=max(mx,abs(sum()));
    }
    cout<<mx<<'\n';
}
signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t;
    cin>>t;
    while(t--) {
        solve();
    }
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

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

void solve() {
    int l,r;
    cin >> l >> r;
    int a = 0;
    for(int i = 31; i >= 0; i--){
        if(a > l) break;
        if(r & (1 << i)){
            a += (1 << i);
        }
    }
    int b = a - 1;
    int c = l;
    if(a != r) c = r;
    else if( b != l) c = l;
    else c = a-2;
    cout << a <<" " << b << " " << c << endl;
}

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("opp.txt", "w", stdout);
#endif

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

    return 0;
}


Solution 2 (runtime: 109 ms):
#include<bits/stdc++.h>
#define int long long int
using namespace std;
signed main()
{
    int t;
    cin>>t;
    while(t--){
      int l,r;
      cin>>l>>r;
      int ans=0,a=0,b=0,c=0;
     for (int i = 30; i >= 0; i--)
    {
        int b1 = 0;
        int b2 = 0;
        if (l & (1ll << i))
        {
            b1 = 1;
        }
        if (r & (1ll << i))
        {
            b2 = 1;
        }
        if (b1 == b2)
        {
            ans += b1 * (1ll << i);
        }
        else
        {
            a = ans + (1ll << i);
            b = a - 1;
            break;
        }
    }
      for(int i=l;i<=r;i++){
        if(i!=a && i!=b){
            c=i;
            break;
        }
      }
      cout<<a<<" "<<b<<" "<<c<<endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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

using namespace std;

int main(){
    int t, n, k, r;
    map <int, int> A;
    vector <pair <int, int>> B;

    cin >> t;
    while(t--){
        A.clear();
        B.clear();

        cin >> n >> k;

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

        for(auto v: A)
            B.push_back({v.second, v.first});
        sort(B.begin(), B.end());

        int i;
        for(i=0; i < B.size() && B[i].first <= k; k -= B[i].first, i++);

        cout << (int)(max(1, (int)B.size()-i)) << '\n';
    }
    return 0;
}


Solution 2 (runtime: 187 ms):
#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);
        for(int i=0;i<n;i++)
        {
           cin>>arr[i];
        }
        vector<int>count(n,0);
        sort(arr.begin(),arr.end());
        int j=0;
        for(int i=0;i<n;i++)
        {
            if(arr[i]==arr[i-1])
            {
                count[j]++;
            }
            else{
                if(i!=0) j++;
                count[j]++;
            }
        }
        sort(count.begin(),count.end());
        int result=0;
      for(int i=0;i<count.size();i++)
      {
         if(count[i]==0)
         {
            continue;
         }
         if(count[i]>k)
         {
            result++;
            continue;
         }
         if(count[i]==k)
         {
            if(i==count.size()-1) result++;
            k-=count[i];
            continue;
         }
         if(count[i]<k)
         {
          k-=count[i];
         }
      }     
      if(result) cout<<result<<endl;
      else cout<<"1\n";  
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

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

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

// ababa

// baba                  aaba
// bba aba              aba    
// ba   ba  aa         ba   aa
// a b  a b a  

// 9  

// abcde

// acde    bcde
// ade cde  bde 
// ae de  ce  be 

// a b c d e

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




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

#define MULTITEST
#define PROBLEM_NAME template
// #define LEGACY

//////////////
using namespace std;
typedef long long ll; 
const ll INF = 2*1024 * 1024 * 1023; 
const char nl = '\n';
#define forn(i, n) for (int i = 0; i < int(n); i++) 
#define matrl(xc,yc,x,y) for (int yc=0;yc<int(y);++yc) for (int xc=0;xc<int(x);++xc)
#define all(v) v.begin(),v.end() 
#define nl() cout<<nl
#pragma GCC optimize("O2")
void printm(vector<vector<int>> vis){for (auto it : vis) {for (auto i : it) cout<<i<<" ";cout<<"\n";}}
void printvec(vector<int> vec){for (auto it: vec) cout<<it<<" ";cout<<"\n";}
#if defined(MULTITEST)
bool multiTest=true;
#else 
bool multiTest=false;
#endif

vector<ll> a(1010);
void solve(int tt){
	int n;cin>>n;
	for (int i=1;i<=n;++i)cin>>a[i];
	int now=n;
	ll ans=-1*INF;
	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 << nl; 
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	#ifdef LEGACY 
	freopen("PROBLEM_NAME.in","r",stdin);
	freopen("PROBLEM_NAME.out","w",stdout);
	#endif
    cout << fixed << setprecision(14);
    int t = 1;
    if (multiTest) cin >> t;
    for (int ii = 0; ii < t; ii++) {
        solve(ii);;
    }
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

using namespace std;



// Yash Raj 2112047

#define ll long long

#define ld long double

#define pb push_back

#define mp make_pair

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

#define rall(v) (v).rbegin(), (v).rend()

#define sz(x) (int)(x).size()

#define F first

#define S second



// Fast Input/Output

void fast_io() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

}



// Debugging (for personal use during development)

#define debug(x) cerr << #x << " = "; _print(x); cerr << endl;

template <typename T> void _print(T x) { cerr << x; }

template <typename T, typename V> void _print(pair<T, V> p) { cerr << "{" << p.F << "," << p.S << "}"; }

template <typename T> void _print(vector<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; }



int main() {

    fast_io(); // Ensures fast input/output

    

    int t;

    cin >> t; // Multiple test cases

    while (t--) {

        

        ll n, l, r;

        cin >> n>>l>>r;

        --l;

        vector<ll> arr(n);

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

            cin >> arr[i];

        }

        vector<ll>b = arr;

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

        vector<ll>c = arr;

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

        ll sum1 = accumulate(b.begin()+l, b.begin()+r, 0LL);

        ll sum2 = accumulate(c.begin()+l, c.begin()+r, 0LL);

        

        cout<<min(sum1, sum2)<< "\n";

    }



    return 0;

}

Solution 2 (runtime: 124 ms):
#include "bits/stdc++.h"

using namespace std;

 

#define ll long long

 

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

#define         rall(v)              v.rbegin(),v.rend()

 

#define            pb                push_back

#define          sz(a)               (int)a.size()

 





void solve() {

    ll n, l,r;

    cin>>n>>l>>r;



     l--;

     r--;

    vector<ll> a(n);

   



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

        cin>>a[i];

    }



    vector<ll> b,c;



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

        b.push_back(a[i]);

    }

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

        c.push_back(a[i]);

    }



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

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



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

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

   



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



}



 

int32_t main() {

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int t;

    cin >> t;

    while(t--) {

        solve();

    }

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

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

using namespace std;

void solve() {
    int n; cin >> n;
    vector<long long> a(n);
    long long mx = 0;
    for (auto& aa: a) {
        cin >> aa;
        mx += aa;
    }
    while (a.size() > 1) {
        vector<long long> change;
        for (int i = (int)a.size() - 2; i >= 0; --i) change.push_back(a[i] - a[i + 1]);
        long long cur = 0;
        for (auto cc : change) cur += cc;
        mx = max(cur, mx);
        mx = max(mx, -cur);
        a = change;
    }
    cout << mx << endl;
}

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


Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
void solve()
{
    i64 n;
    cin >> n;
    vector<i64> f(n);
    i64 ans = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> f[i];
        ans += f[i];
    }
    if (n == 1)
    {
        cout << ans << "\n";
        return;
    }
    auto check = [&](int i) -> i64
    {
        i64 ans = f[n - 1] - f[i];
        for (int j = n - 1; j > i; j--)
        {
            f[j] -= f[j - 1];
        }
        if (n - 1 == i + 1)
        {
            return abs(f[n - 1]);
        }
        return abs(ans);
    };
    for (int i = 0; i < n - 1; i++)
    {
        ans = max(ans, check(i));
    }
    cout << ans << '\n';
    return;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}