ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 93 ms):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string a,b,c;
ll n,m;
ll f(ll i,ll j,vector<vector<ll>>&dp){
    if(i>=n&&j>=m) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    ll o1 = 1e12, o2 = 1e12;
    if(i<n){
        o1 = (a[i]!=c[i+j]) + f(i+1,j,dp);
    }
    if(j<m){
        o2 = f(i,j+1,dp) + (b[j]!=c[i+j]);
    }
    return dp[i][j] = min(o1,o2);
}

void solve(){
    cin>>a>>b>>c;
    n = a.length(), m = b.length();
    ll N = 3e3;
    vector<vector<ll>> dp(n+10,vector<ll>(m+10,-1));
    ll ans = f(0,0,dp);
    cout<<ans<<endl;
}
int main()
{
    ll t; cin>>t;
    while(t--) solve();

    return 0;
}

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

using namespace std;



#define int long long

#define ll long long



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

#define sum(a) (accumulate((a).begin(), (a).end(), 0ll))

#define mine(a) (*min_element((a).begin(), (a).end()))

#define maxe(a) (*max_element((a).begin(), (a).end()))

#define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin())

#define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

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



#define nl cout << "\n";

#define op(x) cout << x << "\n";

#define opp(x, y) cout << x << " " << y << "\n";

const int MOD = 1e9 + 7;

const int N = 1e5 + 10;

bool revsort(ll a, ll b) { return a > b; }



/*--------------------------------------------------------------------------------------------------------------------------*/

void solve()

{

    string a, b, c;

    cin >> a >> b >> c;



    int na = a.length(), nb = b.length(), nc = c.length();



    vector<vector<int>> dp(na + 1, vector<int>(nb + 1, -1));

    auto help = [&](int ia, int ib, auto &self) -> int

    {

        if (ia == na && ib == nb)

        {

            return dp[ia][ib] = 0;

        }



        if(dp[ia][ib] != -1){

            return dp[ia][ib];

        }



        int c1, c2, c3, c4;

        c1 = c2 = c3 = c4 = INT_MAX;



        if (ia < na && a[ia] == c[ia + ib])

        {

            c1 = self(ia + 1, ib, self);

        }

        else if (ia < na && a[ia] != c[ia + ib])

        {

            c2 = self(ia + 1, ib, self) + 1;

        }



        if (ib < nb && b[ib] == c[ia + ib])

        {

            c3 = self(ia, ib + 1, self);

        }

        else if (ib < nb && b[ib] != c[ia + ib])

        {

            c4 = self(ia, ib + 1, self) + 1;

        }

        return dp[ia][ib] = min({c1, c2, c3, c4});

    };



    int ans = help(0, 0, help);

    op(ans);

}



signed main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    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;

vector<int> reverseArray(vector<int> &arr) {
    vector<int> ret;
    int n=arr.size();
    for (int i=n-1;i>=0;i--){
        ret.push_back(arr[i]);
    }
    return ret;
}

vector<long long> diffArray(vector<long long> &arr) {
    vector<long long> ret;
    int n=arr.size();
    for(int i=1;i<n;i++) {
        ret.push_back(arr[i] - arr[i-1]);
    }
    return ret;
}

long long sumOf(vector<long long> &arr) {
    long long ans = 0ll;
    for(long long i: arr) {
        ans+=i;
    }
    return ans;
}

void solve(){
    int n;
    cin>>n;
    vector<long long> a(n,0ll);
    for (auto &i:a) {
        cin>>i;
    }
    long long ans = sumOf(a);
    while(n>1) {
        a = diffArray(a);
        ans=max(ans, abs(sumOf(a)));
        n--;
    }
    cout<<ans<<'\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Solution 2 (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);
    for(int i=0;i<n;i++)
    cin>>arr[i];
    long long ans=accumulate(arr.begin(),arr.end(),0LL);
    vector<long long> v;
    while(n>1){
       for(int i=0;i<n-1;i++){
           v.push_back(arr[i+1]-arr[i]);
       }
       ans=max(ans,abs(accumulate(v.begin(),v.end(),0LL)));
       for(int i=0;i<n-1;i++)
       arr[i]=v[i];
       v.clear();
       n--;
    }
    cout<<ans<<endl;
}
}
Problem: 2050D - Digital string maximization
Language: c++17 

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

using namespace std;

inline string solve() {
    string s;
    cin >> s;
    
    for (int i = 1; i < s.size(); i++) {
        if (s[i] == '0')
            continue;
        
        if (s[i] - '1' > s[i - 1] - '0') {
            char c = s[i - 1];
            s[i - 1] = s[i] - 1;
            s[i] = c;
            
            for (int j = i - 1; j > 0; j--) {
                if (s[j] - '1' > s[j - 1] - '0') {
                    char d = s[j -1];
                    s[j - 1] = s[j] - 1;
                    s[j] = d;
                }
                else
                    break;
            }
        }
    }
    
    return s;
}

int main() {
    int tests;
    cin >> tests;
    vector<string> output(tests);
    for (int i = 0; i < tests; i++) {
        output[i] = solve();
    }
    for (int i = 0; i < tests; i++) {
        cout << output[i] << endl;
    }
}


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

using namespace std;

void solve(){

string s;

cin>>s;

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

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

if(s[i]+j-i<s[j]){

int temp=s[j]+i-j;

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

s[i]=temp;

// cout<<s<<"\n";

}

}

}

cout<<s<<"\n";

}

int main(){

ios::sync_with_stdio(0);

cin.tie(0);

int _; cin>>_;

while(_--) solve();

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

Solution 1 (runtime: 77 ms):
// Handle: akhilpranjal

// Date: 05-02-2025

// Time: 17:12

 

#include<bits/stdc++.h>

using namespace std;

 

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

#define vll vector<long long>

#define ll long long

#define ull unsigned long long

#define ld long double

#define F first

#define S second

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

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

 

// Operator Overloads:

 

template<typename T1, typename T2>     // cin >> pair<T1,T2>

istream& operator>>(istream &istream, pair<T1,T2> &p) { return (istream >> p.first >> p.second); }

 

template<typename T>     // cin >> vector<T> &v

istream& operator>>(istream &istream, vector<T> &v)

{

    for(auto &it : v)

    {

        cin >> it;

    }

    return istream;

}

 

template<typename T1, typename T2>     // cout << pair<T1,T2>

ostream& operator<<(ostream &ostream, const pair<T1,T2> &p) { return(ostream << p.first << " " << p.second); }

 

template<typename T>     // cout << vector<T>

ostream& operator<<(ostream &ostream, const vector<T> &v) { for (auto &it : v) cout << it << " "; return ostream; }

 

 

 

void solve()

{

    ll n,l,r,sum1=0,sum2=0;

    cin>>n>>l>>r;

    l--;r--;

    vll a(n),b;

    cin>>a;

    b=a;

    // ll x = r-l+1;

    sort(a.begin(),a.begin()+r+1);

    rep(i,0,r-l+1)

    {

        sum1 += a[i];

    }

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

    rep(i,l,r+1)

    {

        sum2 += b[i];

    }

    cout<<min(sum1,sum2);



    

    



}

 

 

int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

 

    ll t;

    cin >> t;

    for(int i=1;i<=t;i++) {

        solve();

        cout<<endl;

    }

    return 0;

}

Solution 2 (runtime: 202 ms):
 /*





        In the name of Allah





*/

#include <bits/stdc++.h>

#define ll long long

#define ld long double

#define endl "\n"

using namespace  std;

/*





        Inshaallah





*/



using namespace std;

const int val=(1e5 + 5);

const int mod = 1e9;

ll binpow(ll x , ll n)

{

    ll ans = 1;

    while(n > 0)

    {

        if(n % 2)

        {

            n--;

            ans = ans * x % mod;

        }

        else

        {

            n /= 2;

            x = x * x % mod;

        }

    }

    return ans;

}

void dfs(ll x, ll y)

{



}

void solve()

{

    ll n, l, r;

    cin >> n >> l >> r;

    ll ar[n];

    vector<int> vc;

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

    {

        cin >> ar[i];

        if(i < r)

        {

            vc.push_back(ar[i]);

        }

    }

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

    ll s = 0;

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

    {

        s += vc[i];

    }

    ll mn = s;

    s = 0;

    vector<int> vc1;

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

    {

        vc1.push_back(ar[i]);

    }

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

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

    {

        s = s + vc1[i];

    }

    cout << min(mn, s) << endl;

}

int main()

{

    int t;

    cin >> t;

    while(t --)

    {

        solve();

    }

}

/*





        Alhamdullilah





*/
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 2421 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
map<vector<ll>, ll>mp;
ll f(string &a, string &b, string &c, int na, int nb, int i, int j, int k){
    if(k==na+nb) return 0;
    if(mp[{i,j,k}]){
        return mp[{i,j,k}]-1;
    }
    ll ans = na+nb;
    // select the elem from string a
    if(i<na){
        ll x = f(a, b, c, na, nb, i+1, j, k+1);
        if(c[k]==a[i]){
            ans = min(x, ans);
        }
        else{
            ans = min(ans, 1+x);
        }
    }
    if(j<nb){
        ll x = f(a, b, c, na, nb, i, j+1, k+1);
        if(c[k]==b[j]){
            ans = min(x, ans);
        }
        else{
            ans = min(ans, 1+x);
        }
    }
    mp[{i,j,k}] = ans+1;
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--){
        mp.clear();
        string a, b, c;
        cin>>a>>b>>c;
        ll na=a.size(), nb=b.size();
        cout<<f(a, b, c, na, nb, 0, 0, 0)<<"\n";
    }
}

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

int dp[1001][1001];

int f(int index1, int index2, string &a, string &b, string &c) {
    if (index1 == a.size() && index2 == b.size()) {
        return 0;
    }

    if (dp[index1][index2] != -1) return dp[index1][index2];

    int cnt = INT_MAX;

    if (index1 < a.size()) {
        int mismatch = (c[index1 + index2] != a[index1]) ? 1 : 0;
        cnt = min(cnt, mismatch + f(index1 + 1, index2, a, b, c));
    }

    if (index2 < b.size()) {
        int mismatch = (c[index1 + index2] != b[index2]) ? 1 : 0;
        cnt = min(cnt, mismatch + f(index1, index2 + 1, a, b, c));
    }

    return dp[index1][index2] = cnt;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;

        memset(dp, -1, sizeof(dp));

        cout << f(0, 0, a, b, c) << endl;
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

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

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

    vector<int> list_of_ints(length);
    for (int i = 0; i < length; i++) {
        cin >> list_of_ints[i];
    }

    vector<int> original_list(length);
    for (int i = 0; i < length; i++) {
        original_list[i] = i + 1;
    }

    int answer = 0;

    if (length == 1) {
        cout << "0" << endl;
    } 
    else if (length == 2 && list_of_ints == vector<int>{1, 2}) {
        cout << "2" << endl;
        cout << "2 1" << endl;
        cout << "1 2" << endl;
    } 
    else if (length == 2 && list_of_ints == vector<int>{2, 1}) {
        cout << "1" << endl;
        cout << "2 1" << endl;
    } 
    else {
        int i = 0;
        while (i < length) {
            int j = find(original_list.begin(), original_list.end(), list_of_ints[i]) - original_list.begin();
            answer += ((length - 1) - j) + ((length - 1) - i);
            original_list.erase(original_list.begin() + j);
            original_list.insert(original_list.begin() + i, list_of_ints[i]);
            i++;
        }
        cout << answer << endl;

        i = 0;
        original_list.clear();
        for (int k = 0; k < length; k++) {
            original_list.push_back(k + 1);
        }

        while (i < length) {
            int j = find(original_list.begin(), original_list.end(), list_of_ints[i]) - original_list.begin();
            original_list.erase(original_list.begin() + j);

            while (j != (length - 1)) {
                cout << original_list[j] << " " << list_of_ints[i] << endl;
                j++;
            }
            while (j != i) {
                j--;
                cout << list_of_ints[i] << " " << original_list[j] << endl;
            }
            original_list.insert(original_list.begin() + i, list_of_ints[i]);
            i++;
        }
    }

    return 0;
}


Solution 2 (runtime: 1265 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
const int mod=1e9+7;
signed main()
{
int t;
t=1;
while(t--)
{
  int n;
  cin >> n;
  vector<int> arr(n);
  vector<pair<int,int>> mp;
  map<int,int> ind;
  for(auto& i:arr) cin >> i;
  for(int i=0;i<n;i++)
  ind[arr[i]]= i;
  for(int i = 1;i<=n;i++){
         for(int j=i+1;j<=n;j++){
                 mp.push_back({i,j}); 
         }
  }
  vector<int> temp(n);

  for(int i=0;i<n;i++){
      temp[i] = n-i;
  }
      for(int i=1;i<n;i++){
              int j = i;
              while(j && ind[temp[j]] < ind[temp[j-1]]){
                    mp.push_back({temp[j-1],temp[j]});
                    swap(temp[j-1],temp[j]);
                    j--;
              }
      }
      cout << mp.size() << endl;
      for(auto& i:mp){
        cout << i.second <<" " << i.first << endl;
      }

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

Solution 1 (runtime: 374 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define loop(n) for(int i=0;i<n;i++)
#define pb push_back
const int mod = 1e9+7;
 
void solve(){
int n;
cin>>n;
int a[n];
loop(n) cin>>a[i];
int ans=1;
if(a[0]>a[1]) ans=0;
else{
for(int i=0;i<n-1;i++){
int mini=min(a[i],a[i+1]);
a[i]-=mini;
a[i+1]-=mini;
}
}
loop(n-1){
if(a[i]>a[i+1]){ans=0;break;}
}
if(ans==1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
 
int32_t main(){
int t;
cin>>t;
while(t--) solve();
return 0;
}

Solution 2 (runtime: 108 ms):
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define all(x) x.begin(), x.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long

void solve(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n-1; i++){
        int k = min(a[i],a[i+1]);
        a[i] -= k;
        a[i+1] -= k;
    }
    vector<int> v = a;
    sort(all(v));
    cout << ((v == a) ? "YES\n" : "NO\n");
}

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

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

using namespace std;

const int N=1e5+1;

typedef long long ll;

ll t,a[N],b[N];

int main(){

	scanf("%lld",&t);

	while(t--){

		ll n,l,r,sum1=0,sum2=0;

		memset(a,0,sizeof(a));

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

		scanf("%lld%lld%lld",&n,&l,&r);

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

			scanf("%lld",&a[i]);

			b[i]=a[i];

		}

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

		sort(b+l,b+n+1);

		for(int i=1;i<=r-l+1;i++) sum1+=a[i];

		for(int i=l;i<=r;i++) sum2+=b[i];

		ll ans=min(sum1,sum2);

		printf("%lld\n",ans);

	}

	return 0;

}



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

using namespace std;



#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

#define int long long



signed main(){

    fastio;

    int t; cin >> t;

    while(t--){

        int n, l, r; cin >> n >> l >> r;

        vector<int> prev, cur, next;

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

            int x; cin >> x;

            if(i < l) prev.push_back(x);

            if(i >= l && i <= r) cur.push_back(x);

            if(i > r) next.push_back(x);

        }



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

        sort(cur.rbegin(), cur.rend());

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



        int sum = 0, sum2 = 0, i = 0, j = 0;

        for(int i = 0, j = 0; i < cur.size(); i++){

            if(j >= next.size() || cur[i] < next[j]){

                sum += cur[i];

            }

            else sum += next[j];

            j++;

        }



        for(int i = 0, j = 0; i < cur.size(); i++){

            if(j >= prev.size() || cur[i] < prev[j]){

                sum2 += cur[i];

            }

            else sum2 += prev[j];

            j++;

        }



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

        

    }

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

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

int main(){
    int t;
    cin >> t;
    while(t--){
      long long n;
        cin >> n;
        long long a[n];
        vector<long long int>v;
        long long ans = 0;
        for(int i=0;i<n;i++){
            cin >> a[i];
            ans+=a[i];
            v.push_back(a[i]);
        }
        vector<long long int>curr;
        while(v.size()>1){
            
            long long  sum = 0;
            for(int i=1;i<v.size();i++){
               curr.push_back(v[i]-v[i-1]);
                sum+=(v[i]-v[i-1]);
            }
            
            v.clear();
            v = curr;
            curr.clear();
            ans = max(ans, abs(sum));
        }
        cout << ans << endl;
    }
}



Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
typedef long long ll;
int n;
ll a[N];
int main()
{
    // freopen("1.in", "r", stdin);
    // freopen("1.out", "w", stdout);
    int T;
    scanf("%d", &T);
    while(T --)
    {
        scanf("%d", &n);
        ll ans = 0;
        for (int i = 1; i <= n; ++ i) scanf("%lld", &a[i]), ans += a[i];
        int m = n;
        for (int i = 1; i <= n - 1; ++ i)
        {
            ll val = 0;
            // printf("!!!\n");
            for (int j = 1; j <= m - 1; ++ j) a[j] = a[j + 1] - a[j], val += a[j];
            ans = max(ans, abs(val));
            m --;
        }
        printf("%lld\n", ans);
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        int a[n + 1];
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
        }

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

        for (int i = 1; i < n; i++)
        {
            if (a[i] > a[i + 1])
            {
                flag = 1;
                break;
            }
        }

        if (flag)
        {
            cout << "NO" << "\n";
        }
        else
        {
            cout << "YES" << "\n";
        }
    }
}

Solution 2 (runtime: 328 ms):
#include <iostream>     // std::cout

#include <algorithm>    // std::random_shuffle

#include <vector>       // std::vector

#include <map>          // std::map

#include <ctime>        // std::time

#include <cstdlib>      // std::rand, std::srand

#include <string>

#include <cmath>



int main() {

int testcount;

std::cin >> testcount;

for (int test = 0; test < testcount; test++) {

int n, fl = 0;

long long res;

std::cin >> n >> res;

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

long long tmp;

std::cin >> tmp;

if (res > tmp || fl) fl = true;

else res = tmp - res;

}

if (fl) std::cout << "NO\n";

else std::cout << "YES\n";



}

return 0;

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

Solution 1 (runtime: 109 ms):
#include<bits/stdc++.h>
using namespace std;
    //Types
typedef long long ll;
typedef pair<ll,ll> pp;
typedef map<int,int> mpp;
typedef vector<int> vv;
typedef vector<ll> vll;
typedef vector<pp> vpp;
    //Defines
#define T int t;cin>>t;while(t--)
#define N ll n;cin>>n;
#define Nk ll n,k;cin>>n>>k;
#define f(i,a,b) for(int i=a; i<=b; i++)
#define fg(i,a,b,c) for(int i=a; i<=b; i+=c)
#define ff(i,a,b) for(int i=a; i>=b; i--)
#define ffg(i,a,b,c) for(int i=a; i>b; i-=c)
#define aa(n) int arr[n+1];for(int i=1; i<=n; i++){cin>>arr[i];}
#define la(n) ll arr[n+1];for(ll i=1; i<=n; i++){cin>>arr[i];}
#define amn(n) int mn=1e9+7,arr[n+1];for(int i=1; i<=n; i++){cin>>arr[i];mn=min(mn,arr[i]);}
#define lan(n) ll mn=1e18+18,arr[n+1];for(int i=1; i<=n; i++){cin>>arr[i];mn=min(mn,arr[i]);}
#define amx(n) int mx=0,arr[n+1];for(int i=1; i<=n; i++){cin>>arr[i];mx=max(mx,arr[i]);}
#define lax(n) ll mx=0,arr[n+1];for(int i=1; i<=n; i++){cin>>arr[i];mx=max(mx,arr[i]);}
#define lap(n) ll arr[n+1],ps[n+1]={0};for(int i=1; i<=n; i++){cin>>arr[i]; ps[i]=ps[i-1]+arr[i];}
#define pb push_back
#define mk make_pair
#define lb lower_bound
#define ub upper_bound
#define neh cout<<"No"<<endl
#define ya cout<<"Yes"<<endl

int gcd(int a,int b) {
    if(b==0) return a;
    return gcd(b,a%b);
}

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

ll modpow(ll a,ll b,ll m) {
    if(b==0) return 1%m;
    ll x = modpow(a,b/2,m);
    x=(x*x)%m;
    if(b%2==1) x=(x*a)%m;
    return x;
}

void solve() {
    ll n,l,r,x,sum1=0; cin>>n>>l>>r;
    vll a,b;
    f(i,1,n) {
        cin>>x;
        if(i<=r) a.pb(x);
        if(i>=l) b.pb(x);
        if(i>=l && i<=r) sum1+=x;
    }
    sort(a.begin(),a.end()); sort(b.begin(),b.end());
    ll sum2=0,sum3=0;
    f(i,0,r-l) {sum2+=a[i]; sum3+=b[i];}
    sum1=min(sum1,sum2);
    sum1=min(sum1,sum3);
    cout<<sum1<<endl;
}

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

    T solve();

    return 0;
}


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

#include <vector>

#include <map>

#include <stack>

#include <string>

#include <queue>

#include <set>

#include <algorithm>

#include <math.h>

#include <cassert>

using namespace std;

typedef long long ll;

const ll nmax=1e18, mod=1e9+7, mod1=998244353, ng=2e5+1;



int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);cout.tie(NULL);



    ll t;cin >> t;

    while(t--){

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

        vector <ll> v1, v2;

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

            ll ca;cin >> ca;

            if(i < r)v1.push_back(ca);

            if(i >= l-1)v2.push_back(ca);

        }

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

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



        ll ca1 = 0, ca2 = 0;

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

            ca1 += v1[i];

            ca2 += v2[i];

        }

        cout << (min(ca1, ca2)) << endl;

    }



	return 0;

}