ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: c++20 

Code 1:
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int maxN=2e3;
const int INF=1e9;
const int MOD=1e9+7;

int t, n, l, r, ans1, ans2, a;
vi arr1, arr2;

signed main(){
    fastio();
    cin >> t;
    while(t--){
        cin >> n >> l >> r;
        arr1.clear();
        arr2.clear();
        l--; r--;
        for(int i=0; i<n; i++){
            cin >> a;
            if(i<=r) arr1.pb(a);
            if(i>=l) arr2.pb(a);
        }
        ans1=ans2=0;
        sort(all(arr1));
        sort(all(arr2));
        for(int i=0; i<=r-l; i++){
            ans1+=arr1[i];
            ans2+=arr2[i];
        }
        cout << min(ans1, ans2) << endl;
    }
    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int maxN=2e3;
const int INF=1e9;
const int MOD=1e9+7;

int t, n, l, r, ans1, ans2;
vi arr, a1, a2;

bool invComp(int a, int b){
    return a>=b;
}

signed main(){
    fastio();
    cin >> t;
    while(t--){
        cin >> n >> l >> r;
        arr.resize(n, 0);
        for(int i=0; i<n; i++){
            cin >> arr[i];
        }
        l--; r--;
        a1=a2=arr;
        sort(a1.begin(), a1.begin()+r+1, invComp);
        sort(a2.begin()+l, a2.end());
        ans1=ans2=0;
        for(int i=l; i<=r; i++){
            ans1+=a1[i];
            ans2+=a2[i];
        }
        cout << min(ans1, ans2) << endl;
    }
    return 0;
}


Answer: 1
Problem: 2063B - Subsequence Update
Language: c++23 

Code 1:
#include <bits/stdc++.h>

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

using namespace std;

using ll = long long;

void solve() {
    ll n, l, r;
    cin >> n >> l >> r;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<ll> x, y;
    for (ll i = 0; i < r; ++i) {
        x.push_back(a[i]);
    }
    for (ll i = l - 1; i < n; ++i) {
        y.push_back(a[i]);
    }
    sort(all(x));
    sort(all(y));
    ll ans1 = 0, ans2 = 0;
    for (ll i = 0; i < r - l + 1; ++i) {
        ans1 += x[i];
    }
    for (ll i = 0; i < r - l + 1; ++i) {
        ans2 += y[i];
    }
    cout << min(ans1, ans2) << endl;
}

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


Code 2:
#include <bits/stdc++.h>



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



using namespace std;



using ll = long long;



void solve() {

    ll n, l, r;

    cin >> n >> l >> r;

    vector<ll> a(n);

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

        cin >> a[i];

    }

    sort(all(a));

    ll s = 0;

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

        s += a[i];

    }

    cout << s << endl;

}



signed main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}



Answer: 1
Problem: 2063B - Subsequence Update
Language: c++20 

Code 1:
#include<iostream>

#include<vector>

#include<algorithm>

#include<unordered_map>

#include<utility>

#include<string>

using namespace std;

typedef long long ll;



int t;



bool comp(int a, int b){

    return a > b;

}



void solve(){

    int n, l, r;

    int sum = 0;

    cin>>n>>l>>r;

    vector<int> a(n);

    l--; r--;

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

        cin >> a[i];

        if(i >= l && i <= r) sum += a[i];

    }



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

    sort(a.begin(), a.begin() + l);

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



    int ptr1 = 0, ptr2 = l, ptr3 = r + 1;

    int sum1 = 0, sum2 = 0, sum3 = 0;

    int ans = sum;



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

        sum1 += a[ptr1];

        sum2 += a[ptr2];

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

        ptr1++; ptr2++;

    }



    ptr2 = l;

    sum2 = 0;



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

        sum3 += a[ptr3];

        sum2 += a[ptr2];

        ans = min(ans, sum - sum2 + sum3);

        ptr3++; ptr2++;

    }



    cout<<ans;

    cout<<endl;

}



int main(){

    cin >> t;

    while(t--){

        solve();

    }

}

Code 2:
#include<iostream>

#include<vector>

#include<algorithm>

#include<unordered_map>

#include<utility>

#include<string>

using namespace std;

typedef long long ll;



int t;



bool comp(int a, int b){

    return a > b;

}



void solve(){

    int n, l, r;

    ll sum = 0;

    cin>>n>>l>>r;

    vector<int> a(n);

    l--; r--;

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

        cin >> a[i];

        if(i >= l && i <= r) sum += a[i];

    }



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

    sort(a.begin(), a.begin() + l);

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



    int ptr1 = 0, ptr2 = l, ptr3 = r + 1;

    ll sum1 = 0, sum2 = 0, sum3 = 0;

    ll ans = sum;



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

        sum1 += a[ptr1];

        sum2 += a[ptr2];

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

        ptr1++; ptr2++;

    }



    ptr2 = l;

    sum2 = 0;



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

        sum3 += a[ptr3];

        sum2 += a[ptr2];

        ans = min(ans, sum - sum2 + sum3);

        ptr3++; ptr2++;

    }



    cout<<ans;

    cout<<endl;

}



int main(){

    cin >> t;

    while(t--){

        solve();

    }

}

Answer: 2
Problem: 2063B - Subsequence Update
Language: c++17 

Code 1:
#include<bits/stdc++.h>

using namespace std;
#define LL long long 
 int  main()
{
     long long t;
     cin>>t;
    while(t--)
    {
         long long n,l,r;
        cin>>n>>l>>r;
        vector<long long >a(n);
        vector<long long >b;
        vector<long long >c;
        for( long long i=0;i<n;i++)
        {
            cin>>a[i];
        }
        l--,r--;
        for( long long i=0;i<=r;i++)
        {
            b.push_back(a[i]);
        }
        for( long long i=l;i<n;i++)
        {
            c.push_back(a[i]);
        }
        sort(b.begin(),b.end());
        sort(c.begin(),c.end());
         long long sum1 = accumulate(b.begin(),b.begin()+int(r-l+1),0LL);
         long long sum2 = accumulate(c.begin(),c.begin()+int(r-l+1),0LL);
        cout<<min(sum1,sum2)<<endl;

        

    }
}

Code 2:
#include<bits/stdc++.h>

using namespace std;
#define LL long long 
int main()
{
    int t;cin>>t;
    while(t--)
    {
        int n,l,r;
        cin>>n>>l>>r;
        vector<int>a(n);
        vector<int>b;
        vector<int>c;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        l--,r--;
        for(int i=0;i<=r;i++)
        {
            b.push_back(a[i]);
        }
        for(int i=l;i<n;i++)
        {
            c.push_back(a[i]);
        }
        sort(b.begin(),b.end());
        sort(c.begin(),c.end());
        int sum1 = accumulate(b.begin(),b.begin()+int(r-l+1),0);
        int sum2 = accumulate(c.begin(),c.begin()+int(r-l+1),0);
        cout<<min(sum1,sum2)<<endl;

        

    }
}

Answer: 1
Problem: 2063B - Subsequence Update
Language: c++17 

Code 1:
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

ll n, l, r;
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int t; cin >> t;

    while(t--) {
        cin >> n >> l >> r;

        priority_queue<ll> mid_l, mid_r;
        priority_queue<ll, vector<ll>, greater<ll>> lqu, rqu;
        ll ans = 0, la = 0, ra = 0;

        for (int i = 1; i < l; i++) {
            ll e; cin >> e;
            lqu.push(e);
        }

        for (int i = l; i <= r; i++) {
            ll e; cin >> e;
            mid_l.push(e); mid_r.push(e);

            ans += e;
        }

        for (int i = r + 1; i <= n; i++) {
            ll e; cin >> e;
            rqu.push(e);
        }


        while(!lqu.empty() && !mid_l.empty()) {
            if (lqu.top() <= mid_l.top()) la += lqu.top() - mid_l.top();
            else break;

            lqu.pop(); mid_l.pop();
        }

        while(!rqu.empty() && !mid_r.empty()) {
            if (rqu.top() <= mid_r.top()) ra += rqu.top() - mid_r.top();
            else break;

            rqu.pop(); mid_r.pop();
        }

        cout << ans + min(min(ra, la), 0LL) << endl;
    }

    return 0;
}

Code 2:
#include <bits/stdc++.h>

#define ll long long

#define endl '\n'



using namespace std;



ll n, l, r;

signed main() {

    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);



    int t; cin >> t;



    while(t--) {

        cin >> n >> l >> r;



        priority_queue<int> mid_l, mid_r;

        priority_queue<int, vector<int>, greater<int>> lqu, rqu;

        int ans = 0, la = 0, ra = 0;



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

            int e; cin >> e;

            lqu.push(e);

        }



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

            int e; cin >> e;

            mid_l.push(e); mid_r.push(e);



            ans += e;

        }



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

            int e; cin >> e;

            rqu.push(e);

        }





        while(!lqu.empty() && !mid_l.empty()) {

            if (lqu.top() <= mid_l.top()) la += lqu.top() - mid_l.top();

            else break;



            lqu.pop(); mid_l.pop();

        }



        while(!rqu.empty() && !mid_r.empty()) {

            if (rqu.top() <= mid_r.top()) ra += rqu.top() - mid_r.top();

            else break;



            rqu.pop(); mid_r.pop();

        }



        cout << ans + min(0, min(ra, la)) << endl;

    }



    return 0;

}

Answer: 1
Problem: 2063B - Subsequence Update
Language: c++17 

Code 1:
//Problem Link :

#include<bits/stdc++.h>

#define ll long long int

#define endl '\n'

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main()

{

    fast;

    ll t;

    cin>>t;

    while(t--)

    {

        ll n,l,r,x;

        cin>>n>>l>>r;

        vector<ll>b,c;

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

        {

            cin>>x;

            if(x>=l && x<=n)b.push_back(x);

            if(x<=r && x>=1)c.push_back(x);

        }

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

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



        ll sum1=0,sum2=0;

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

        {

            sum1+=b[i];

            sum2+=c[i];

        }

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

    }

    return 0;

}





Code 2:
//Problem Link :

#include<bits/stdc++.h>

#define ll long long int

#define endl '\n'

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main()

{

    fast;

    ll t;

    cin>>t;

    while(t--)

    {

        ll n,l,r,x;

        cin>>n>>l>>r;

        vector<ll>b,c;

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

        {

            cin>>x;

            if(i>=l && i<=n)b.push_back(x);

            if(i<=r && i>=1)c.push_back(x);

        }

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

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



        ll sum1=0,sum2=0;

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

        {

            sum1+=b[i];

            sum2+=c[i];

        }

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

    }

    return 0;

}





Answer: 2
Problem: 2063B - Subsequence Update
Language: c++23 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define ll long long 

void input(vector<ll>&a,ll n){
  
  a.resize(n);
  for(ll i=0;i<n;i++){
    cin>>a[i];
  }

}
void printvec(vector<int>&a){
  for(auto num :a){
    cout<<num<<' ';
  }cout<<endl;
}

int main(){
   int test;
   cin>>test;
   while(test--){
    ll n,l,r;
    cin>>n>>l>>r;
    vector<ll>v(n);
    input(v,n);
    vector<ll>b,c;
    r--;l--;
    for(ll i=l;i<n;i++){
       b.push_back(v[i]);
    }
for(ll i=0;i<=r;i++){
  c.push_back(v[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;
    
    



}}


Code 2:
#include <bits/stdc++.h>

using namespace std;

#define ll long long 



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

  

  a.resize(n);

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

    cin>>a[i];

  }



}

void printvec(vector<int>&a){

  for(auto num :a){

    cout<<num<<' ';

  }cout<<endl;

}



int main(){

   int test;

   cin>>test;

   while(test--){

    int n,l,r;

    cin>>n>>l>>r;

    vector<int>v(n);

    input(v,n);

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

    int ans=r-l+1;

    int sum=0;

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

      sum+=v[i];

    }

    cout<<sum<<endl;









}}



Answer: 1
Problem: 2063B - Subsequence Update
Language: c++23 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"

//     priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq; for 3 values input
//cout << get<0>(pq.top()) << endl; 
// priority_queue<tuple<int, int, int>> pq;

#define optimizer() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define fraction(a) cout.unsetf(ios::fixed); cout.precision(a); cout.setf(ios::fixed);

void anik() {
ll n,l,r;
cin>>n>>l>>r;
vector<ll> v(n);
for(int i=0;i<n;i++)
{
      cin>>v[i];
}
sort(v.begin(),v.end());
ll dif=r-l;
ll sum=0;
for(int i=0;i<=dif;i++)
{
sum+=v[i];
}

cout<<sum<<endl;

}

int main() {
    optimizer();

    int test;
    cin >> test;
    while (test--) {
        anik();
    }
    return 0;  
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"

//     priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq; for 3 values input
//cout << get<0>(pq.top()) << endl; 
// priority_queue<tuple<int, int, int>> pq;

#define optimizer() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define fraction(a) cout.unsetf(ios::fixed); cout.precision(a); cout.setf(ios::fixed);

void anik() {
ll n,l,r;
cin>>n>>l>>r;
l--;r--;

ll sum=0;
vector<ll> v(n),be,in,af;
for(int i=0;i<n;i++)
{
      cin>>v[i];
      if(i<l){
        be.push_back(v[i]);
      }
       if(i>=l and r>=i){
        in.push_back(v[i]);
        sum+=v[i];
      }
      
        else if(i>r){
            af.push_back(v[i]);
        }
}


// for(int i=0;i<be.size();i++){
//     cout<<be[i]<<" ";
// }
// cout<<endl;
// for(int i=0;i<in.size();i++){
//     cout<<in[i]<<" ";
// }
// cout<<endl;
// for(int i=0;i<af.size();i++){
//     cout<<af[i]<<" ";
// }
// cout<<endl;





sort(be.begin(),be.end());
sort(in.begin(),in.end(),greater<ll>());
sort(af.begin(),af.end());
 
 ll sum1=sum;

int j=0;
int x=0;
while(!be.empty() and j<in.size() and x<be.size()){
    if(be[x]<in[j]){
     sum-=in[j];
     sum+=be[j];
     x++;
    }
    j++;
   
}
j=0;
x=0;

while(!af.empty() and j<in.size() and x<af.size()){
    if(af[x]<in[j]){
     sum1-=in[j];
     sum1+=af[j];
     x++;
    }
    j++;
   
}


cout<<min(sum,sum1)<<endl;
}


int main() {
    optimizer();

    int test;
    cin >> test;
    while (test--) {
        anik();
    }
    return 0;  
}

Answer: 2
Problem: 2063B - Subsequence Update
Language: c++23 

Code 1:
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

typedef long long ll;



void Func() {

    ll n, l, r;

    cin >> n >> l >> r;

    priority_queue<ll, vector<ll>, greater<> > q2,q1;

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

        ll x;

        cin >> x;

        if (i<=r) q1.push(x);

        if (i>=l) q2.push(x);

    }

    ll ans = 0,ans2 = 0;

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

        ans += q1.top();

        q1.pop();

        ans2 += q2.top();

        q2.pop();

    }

    cout << min(ans,ans2) << endl;

}



int main() {

#ifdef LOCAL

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

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

#endif

    int T;

    cin >> T;

    while (T--) {

        Func();

    }

    return 0;

}



Code 2:
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

typedef long long ll;



void Func() {

    ll n, l, r;

    cin >> n >> l >> r;

    priority_queue<ll, vector<ll>, greater<ll> > q2;

    priority_queue<ll> q1;

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

        ll x;

        cin >> x;

        if (l <= i && i <= r) {

            q1.push(x);

        } else {

            q2.push(x);

        }

    }

    while (!q2.empty() && !q1.empty() && q1.top() > q2.top()) {

        q1.pop();

        q1.push(q2.top());

        q2.pop();

    }

    ll ans = 0;

    while (!q1.empty()) {

        ans += q1.top();

        q1.pop();

    }

    cout << ans << endl;

}



int main() {

    int T;

    cin >> T;

    while (T--) {

        Func();

    }

    return 0;

}



Answer: 1
Problem: 2063B - Subsequence Update
Language: c++17 

Code 1:
#include <bits/stdc++.h>

using namespace std;



#define int 			long long int

#define double			long double

#define F			first

#define S 			second

#define pb 			push_back

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

#define vi 			vector<int>

#define pii			pair<int, int>

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

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



void solve() {

	int n, l, r;

	cin >> n >> l >> r;

	vi a(n);

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



	int curr_sum = 0, sum = 0, len = 0, d = r-l+1;

	rep(i, l-1, r) curr_sum += a[i];

	int mn = curr_sum;



	vi prefix(d+1);

	rep(i, 1, d+1) prefix[i] = prefix[i-1] + a[l+i-2];



	rep(i, 0, r-1) {

		if(sum + a[i] < curr_sum) {

			sum += a[i];

			len++;

		}

		else {

			sum = a[i];

			len = 1;

		}

		mn = min(mn, curr_sum - prefix[len] + sum);

		if(len == d) {

			sum -= a[i-r+l];

			len--;

		}

	}

	

	vi suffix(d+1);

	for(int i = d-1; i >= 0; i--) suffix[i] = suffix[i+1] + a[r-d+i];

	

	sum = 0;

	len = 0;



	for(int i = n-1; i >= l; i--) {

		if(sum + a[i] < curr_sum) {

			sum += a[i];

			len++;

		}

		else {

			sum = a[i];

			len = 1;

		}

		mn = min(mn, curr_sum - suffix[d-len] + sum);

		if(len == d) {

			sum -= a[i+r-l];

			len--;

		}

	}

	

	cout << mn << "\n";

}



int32_t main() {

	#ifdef CODE_START

		CODE_START;

	#endif



	int t;	

	cin >> t;

	while(t--) {

		solve();

	}

	return 0;

}



Code 2:
#include <bits/stdc++.h>
using namespace std;

#define int 			long long int
#define double			long double
#define F			first
#define S 			second
#define pb 			push_back
#define all(x) 			x.begin(), x.end()
#define vi 			vector<int>
#define pii			pair<int, int>
#define rep(i, a, b) 		for(int i = a; i < b; i++)
#define CODE_START 		ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);

void solve() {
	int n, l, r;
	cin >> n >> l >> r;
	vi a(n);
	rep(i, 0, n) cin >> a[i];
	vi b;
	rep(i, l-1, r) b.pb(a[i]);
	sort(b.rbegin(), b.rend());
	int d = r-l+1;
	vi prefix(d+1);
	rep(i, 0, d) prefix[i+1] = prefix[i] + b[i];
	
	vi c;
	rep(i, 0, l-1) c.pb(a[i]);
	sort(all(c));

	int sum = 0, mn = prefix[d], len = 0;
	rep(i, 0, (int)c.size()) {
		if(sum + c[i] < prefix[i+1]) {
			sum += c[i];
			mn = min(mn, prefix[d] - prefix[i+1] + sum);
		}
		else break;
		len++;
		if(len == d) break;
	}

	vi e;
	for(int i = n-1; i >= r; i--) e.pb(a[i]);
	sort(all(e));

	sum = 0;
	len = 0;
	rep(i, 0, (int)e.size()) {
		if(sum + e[i] < prefix[i+1]) {
			sum += e[i];
			mn = min(mn, prefix[d] - prefix[i+1] + sum);
		}
		else break;
		len++;
		if(len == d) break;
	}

	cout << mn << "\n";
}

int32_t main() {
	#ifdef CODE_START
		CODE_START;
	#endif

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


Answer: 2
Problem: 2063B - Subsequence Update
Language: c++20 

Code 1:
// B. Subsequence Update

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

const int N = 2e5 + 10;
int gA[N];

signed main() {
	ios::sync_with_stdio(false);
	
	int t;
	cin >> t;
	
	while (t--) {
		int n, l, r;
		cin >> n >> l >> r;
		
		for (int i = 1; i <= n; i++)
			cin >> gA[i];
		
		priority_queue<int, vector<int>, greater<int> > lft, rht;
		priority_queue<int> mid;
		
		int ans = 0;
		for (int i = l; i <= r; i++)
			ans += gA[i];
		
		int tmpans = ans;
		for (int i = 1; i < l; i++) lft.push(gA[i]);
		for (int i = l; i <= r; i++) mid.push(gA[i]);
		for (int i = r + 1; i <= n; i++) rht.push(gA[i]);
		
		auto tmp = mid; 
		while (lft.size() && mid.size() && lft.top() < mid.top()) ans -= mid.top() - lft.top(), mid.pop(), lft.pop();
		
		int mn = ans; ans = tmpans;
		while (rht.size() && mid.size() && rht.top() < mid.top()) ans -= mid.top() - rht.top(), mid.pop(), rht.pop();
		
		cout << min(mn, ans) << endl; 
	}
	
	return 0;
}

Code 2:
// B. Subsequence Update



#include <bits/stdc++.h>

using namespace std;

#define int long long



const int N = 2e5 + 10;

int gA[N];



signed main() {

	ios::sync_with_stdio(false);

	

	int t;

	cin >> t;

	

	while (t--) {

		int n, l, r;

		cin >> n >> l >> r;

		

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

			cin >> gA[i];

		

		priority_queue<int, vector<int>, greater<int> > lft, rht;

		priority_queue<int> mid;

		

		int ans = 0;

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

			ans += gA[i];

		

		int tmpans = ans;

		for (int i = 1; i < l; i++) lft.push(gA[i]);

		for (int i = l; i <= r; i++) mid.push(gA[i]);

		for (int i = r + 1; i <= n; i++) rht.push(gA[i]);

		

		auto tmp = mid; 

		while (lft.size() && mid.size() && lft.top() < mid.top()) ans -= mid.top() - lft.top(), mid.pop(), lft.pop();

		

		int mn = ans; ans = tmpans; mid = tmp;

		while (rht.size() && mid.size() && rht.top() < mid.top()) ans -= mid.top() - rht.top(), mid.pop(), rht.pop();

		

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

	}

	

	return 0;

}

Answer: 2
Problem: 2063B - Subsequence Update
Language: c++20 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007

void solve(){
    int n, l, r; cin >> n >> l >> r;

    vector<int> v(n);
    for(auto &x : v) cin >> x;

    sort(v.begin(), v.end());
    
    long long sum = 0;
    for(int i = 0; i < (r - l + 1); i++){
        sum += v[i];
    }

    cout << sum << "\n";
}   

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

    int t; cin >> t;
    while (t--) solve();
    return 0;
}


Code 2:
#include <bits/stdc++.h>

using namespace std;

#define mod 1000000007



void solve(){

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



    vector<int> v(n);

    for(auto &x : v) cin >> x;



    if(l == 1 || r == n){

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

        

        long long sum = 0;

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

            sum += v[i];

        }



        cout << sum << "\n";

        return;

    }

    

    vector<int> left, right;

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



        if(i+1 < l){

            left.push_back(v[i]);

        }else if(i + 1 > r){

            right.push_back(v[i]);

        }else{

            left.push_back(v[i]);

            right.push_back(v[i]);

        }

    }



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

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



    long long suml = 0;

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

        suml += left[i];

    }



    long long sumr = 0;

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

        sumr += right[i];

    }

    cout << min(suml, sumr) << "\n";

}   



int main() {

    ios::sync_with_stdio(0);

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



    int t; cin >> t;

    while (t--) solve();

    return 0;

}



Answer: 2