ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#define datatype int



datatype n,q;

datatype tmp;

char chr;

string str; 

void solve(){

    int l,r;

    cin>>n>>l>>r;

    vector<datatype> arr(n);

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

    {

        cin>>arr[i];

    }

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

    sort(arr.begin()+l,arr.begin()+r );

    sort(arr.begin()+r,arr.end());

    int l1 = min(l-1, r-l+1);

    int l2 = min(n-r, r-l+1);

    long long min1=0;

    long long curr=0;

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

        curr+=arr[i]-arr[r-1-i];

        if(curr<min1)min1=curr;

    }

    curr=0;

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

        curr+=arr[r+i]-arr[r-1-i];

        if(curr<min1)min1=curr;

    }

    for(int i=l-1;i<r;i++)min1+=arr[i];

    cout<<min1;

}

    

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int t = 1;

    cin>>t;

    while(t--){

        solve();

        cout<<endl;

    }

}





//     template <int len = 1>

// void subset_sum(int n) {

//     if (n >= len) {

//         subset_sum<std::min(len*2, maxn)>(n);

//         return;

//     }

Submission (verdict: Accepted):
#include<bits/stdc++.h>

using namespace std;

#define datatype int



datatype n,q;

datatype tmp;

char chr;

string str; 

void solve(){

    int l,r;

    cin>>n>>l>>r;

    vector<datatype> arr(n);

    vector<datatype> arr2(n);

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

    {

        cin>>arr[i];

        arr2[i]=arr[i];

    }

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

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

    int ln = r-l+1;

    long long sum1=0,sum2=0;

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

        sum1+=arr[i];

    }

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

        sum2+=arr2[l+i-1];

    }

    cout<<min(sum1,sum2);

}

    

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int t = 1;

    cin>>t;

    while(t--){

        solve();

        cout<<endl;

    }

}





//     template <int len = 1>

// void subset_sum(int n) {

//     if (n >= len) {

//         subset_sum<std::min(len*2, maxn)>(n);

//         return;

//     }
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
#define inf (1e9)
#define INF (1e18)
#define eps (1e-8)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define Int __int128
typedef long long LL;
mt19937 rnd(time(0));
const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7;
int n, in[N];
vector<int> g[N];

void solve()
{
    int ans = 1;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        g[i].clear();
        in[i] = 0;
    }
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        in[y]++;
        g[y].push_back(x);
        in[x]++;
    }
    int mx = 0, ver;
    for (int i = 1; i <= n; i++) {
        int s = g[i].size();
        if (s > mx) {
            mx = s;
            ver = i;
        }
    }
    ans = g[ver].size();
    for (int v : g[ver]) {
        in[v]--;
    }
    mx = 0;
    for (int i = 1; i <= n; i++) {
        if (i == ver) continue;
        mx = max(mx, in[i]);
    }
    ans += mx - 1;
    cout << ans << endl;
    return;
}

signed main()
{
	// IOS;
    // init();
	int __;
    cin >> __;
    while (__ --)
    solve();
	
	return 0;
}
//-Wl,--stack=1998244353


/*
    
*/

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
#define inf (1e9)
#define INF (1e18)
#define eps (1e-8)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define Int __int128
typedef long long LL;
mt19937 rnd(time(0));
const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7;
int n, in[N], ver, mx = 0;
vector<int> g[N];

void dfs(int u, int fa) {
    if (g[u].size() > mx) {
        mx = g[u].size();
        ver = u;
    }
    for (int v : g[u]) {
        if (v == fa) continue;
        dfs(v, u);
    }
}

void solve()
{
    int ans = 1;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        g[i].clear();
        in[i] = 0;
    }
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        in[y]++;
        g[y].push_back(x);
        in[x]++;
    }
    mx = 0;
    for (int i = 1; i <= n; i++) {
        if (g[i].size() == 1) {
            dfs(i, -1);
            break;
        }
    }
    ans = g[ver].size();
    for (int v : g[ver]) {
        in[v]--;
    }
    mx = 0;
    for (int i = 1; i <= n; i++) {
        if (i == ver) continue;
        mx = max(mx, in[i]);
    }
    ans += mx - 1;
    cout << ans << endl;
    return;
}

signed main()
{
	// IOS;
    // init();
	int __;
    cin >> __;
    while (__ --)
    solve();
	
	return 0;
}
//-Wl,--stack=1998244353


/*
    
*/
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
#define inf (1e9)
#define INF (1e18)
#define eps (1e-8)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define Int __int128
typedef long long LL;
mt19937 rnd(time(0));
const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7;
int n, in[N], ver, mx = 0;
vector<int> g[N];

void dfs(int u, int fa) {
    if (g[u].size() > mx) {
        mx = g[u].size();
        ver = u;
    }
    for (int v : g[u]) {
        if (v == fa) continue;
        dfs(v, u);
    }
}

void solve()
{
    int ans = 1;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        g[i].clear();
        in[i] = 0;
    }
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        in[y]++;
        g[y].push_back(x);
        in[x]++;
    }
    mx = 0;
    for (int i = 1; i <= n; i++) {
        if (g[i].size() == 1) {
            dfs(i, -1);
            break;
        }
    }
    ans = g[ver].size();
    for (int v : g[ver]) {
        in[v]--;
    }
    mx = 0;
    for (int i = 1; i <= n; i++) {
        if (i == ver) continue;
        mx = max(mx, in[i]);
    }
    ans += mx - 1;
    cout << ans << endl;
    return;
}

signed main()
{
	// IOS;
    // init();
	int __;
    cin >> __;
    while (__ --)
    solve();
	
	return 0;
}
//-Wl,--stack=1998244353


/*
    
*/

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
#define inf (1e9)
#define INF (1e18)
#define eps (1e-8)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define Int __int128
typedef long long LL;
mt19937 rnd(time(0));
const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7;
int n, in[N];
vector<int> g[N];

void solve()
{
    int ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        g[i].clear();
        in[i] = 0;
    }
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        in[y]++;
        g[y].push_back(x);
        in[x]++;
    }
    multiset<int> s;
    for (int i = 1; i <= n; i++) {
        s.insert(in[i]);
    }
    for (int i = 1; i <= n; i++) {
        int res = 0;
        s.erase(s.find(in[i]));
        for (auto j : g[i]) {
            s.erase(s.find(in[j]));
            s.insert(in[j] - 1);
        }
        res = in[i] + *s.rbegin() - 1;
        ans = max(ans, res);
        for (auto j : g[i]) {
            s.erase(s.find(in[j] - 1));
            s.insert(in[j]);
        }
        s.insert(in[i]);
    }
    cout << ans << endl;
    return;
}

signed main()
{
	// IOS;
    // init();
	int __;
    cin >> __;
    while (__ --)
    solve();
	
	return 0;
}
//-Wl,--stack=1998244353


/*
    
*/
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
#define inf (1e9)
#define INF (1e18)
#define eps (1e-8)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define Int __int128
typedef long long LL;
mt19937 rnd(time(0));
const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7;
int n, in[N];
vector<int> g[N];

void solve()
{
    int ans = 1;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        g[i].clear();
        in[i] = 0;
    }
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        in[y]++;
        g[y].push_back(x);
        in[x]++;
    }
    int mx = 0, ver;
    for (int i = 1; i <= n; i++) {
        int s = g[i].size();
        if (s > mx) {
            mx = s;
            ver = i;
        }
    }
    ans = g[ver].size();
    for (int v : g[ver]) {
        in[v]--;
    }
    mx = 0;
    for (int i = 1; i <= n; i++) {
        if (i == ver) continue;
        mx = max(mx, in[i]);
    }
    ans += mx - 1;
    cout << ans << endl;
    return;
}

signed main()
{
	// IOS;
    // init();
	int __;
    cin >> __;
    while (__ --)
    solve();
	
	return 0;
}
//-Wl,--stack=1998244353


/*
    
*/
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>
using namespace std;
//                                       Sk Najir
#ifndef ONLINE_JUDGE
#include "db.hpp"
#else
#define dbg(x)
#define dbg2(x, y)
#define dbg3(x, y, z)
#endif
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
// pre_define
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;

// Constants
const int MOD = 1e9 + 7;
int f(int a, int b, int c)
{
    return (a ^ b) + (b ^ c) + (c ^ a);
}

int bit(int n)
{
    int i = 0;
    while (n > 0)
    {
        n >>= 1;
        i++;
    }
    return i;
}
void solve()
{
    int l, r;
    cin >> l >> r;
    int res = (l ^ r);
    int bt = bit(res) - 1;
    int a = l | ((1<<bt)-1);
    int b = a + 1;
    int c = (a == l ? r : l);
    // dbg(f(a, b, c));

    cout << a << " " << b << " " << c << endl;
}

int main()
{
    IOS;

    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++)
        solve();
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
long long power(int x,int y)
{
    long long res=1;
    while(y>0)
    {
        int r=y%2;
        if(r==1)
        {
            res=res*x;
        }
        y=y/2;
        x=x*x;
    }
    return res;
}
int main() {
    int t;
    cin>>t;
    while(t--)
    {
       long long low,l,high,h;
       cin>>low>>high;
       l=low;
       h=high;
       vector<int>v1(35,0),v2(35,0);
       int j=32;
      // long long p=1;
       while(high>0)
       {
           int r1=high%2;
           int r2=low%2;
           v1[j]=r1;
           v2[j]=r2;
           j--;
          
           high=high/2;
           low=low/2;    
         
        }
       // cout<<j<<endl;
        long long z=0;
        int idx;
        for(int i=0;i<=32;i++)
        {
            if(v1[i]==v2[i])
            {
                continue;
            }
            idx=33-i;
           
           z=power(2,idx);
            z--;
            break;
        }
    //     cout<<z<<endl;
      //  cout<<z;
        long long num1=l^z;
        long long num2=h^z;
        if(num1<high)
        {
            cout<<l<<" "<<num1<<" "<<h<<endl;
        }
        else if(num2>low){
             cout<<l<<" "<<num2<<" "<<h<<endl;
        }
        else{
            cout<<l<<" "<<l+1<<" "<<h<<endl;
        }
    }
    
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
//                                       Sk Najir
#ifndef ONLINE_JUDGE
#include "db.hpp"
#else
#define dbg(x)
#define dbg2(x, y)
#define dbg3(x, y, z)
#endif
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
// pre_define
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;

// Constants
const int MOD = 1e9 + 7;
int f(int a, int b, int c)
{
    return (a ^ b) + (b ^ c) + (c ^ a);
}
void call(int l, int r)
{
    int mx = 0;
    for (int i = l; i <= r; i++)
    {
        for (int j = i + 1; j <= r; j++)
        {
            for (int k = j + 1; k <= r; k++)
            {
                mx = max(mx, f(i, j, k));
            }
        }
    }
    //dbg(mx);
    for (int i = l; i <= r; i++)
    {
        for (int j = i + 1; j <= r; j++)
        {
            for (int k = j + 1; k <= r; k++)
            {
                if (f(i, j, k) == mx)
                {
                    cout << i << " " << j << " " << k << endl;
                    return;
                }
            }
        }
    }
}
int bit(int n)
{
    int i = 0;
    while (n > 0)
    {
        n >>= 1;
        i++;
    }
    return i;
}
void solve()
{
    int l, r;
    cin >> l >> r;
    int b = bit(r);
    b--;
    int i = b;
    int c = (1 << b);
    b = c - 1;
    while (b > 0)
    {
        if (b > l)
        {
            cout << b << " " << c << " " << l << endl;

            return;
        }
        else
        {
            i--;
            c = (1 << i);
            b = c - 1;
        }
    }
    call(l, r);
}

int main()
{
    IOS;
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++)
        solve();
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
//                                       Sk Najir
#ifndef ONLINE_JUDGE
#include "db.hpp"
#else
#define dbg(x)
#define dbg2(x, y)
#define dbg3(x, y, z)
#endif
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);

// pre_define
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

// shortcut type
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;

// Constants
const int MOD = 1e9 + 7;

void solve()
{

    int n, l, r;
    cin >> n >> l >> r;
    vl v(n);
    for (auto &i : v)
        cin >> i;
    l--, r--;
    sort(v.begin(), v.begin() + l);
    sort(v.begin() + r + 1, v.end());

    ll mn = 0;
    for (int i = l; i <= r; i++)
        mn += v[i];
    ll S = mn;
    if (r + 1 != n)
    {
        sort(v.begin() + l, v.begin() + r + 1);
        int i = r + 1;
        int j = r;
        ll s = S;
        ll sm = 0;
        while (j >= l and i < n)
        {
            s -= v[j];
            sm += v[i];
            mn = min(mn, s + sm);
            j--;
            i++;
        }
    }
    // dbg2(mn, S);
    if (l != 0)
    {

        //sort(v.begin() + l, v.begin() + r + 1);

        ll sm = S;
        int i = l - 1;
        ll ss = 0;
        while (i >= 0 and r >= l)
        {
            ss += v[i];
            sm -= v[r];
            mn = min(mn, ss + sm);
            i--;
            r--;
        }
    }
    cout << mn << endl;
}

int main()
{
    IOS;
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++)
        solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
//                                       Sk Najir
#ifndef ONLINE_JUDGE
#include "db.hpp"
#else
#define dbg(x)
#define dbg2(x, y)
#define dbg3(x, y, z)
#endif
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);

// pre_define
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

// shortcut type
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;

// Constants
const int MOD = 1e9 + 7;

int f(int i, int pr, bool c, int p, vii &adj)
{
    int mx = max(0, (int)adj[i].size() - p); // Ensure mx is non-negative
    int mr = 0, ml = 0;

    for (auto &j : adj[i])
    {
        if (j == pr)
            continue;
        mr = max(mr, f(j, i, c, 0, adj));
        if (c)
        {
            ml = max(ml, f(j, i, !c, 1, adj));
        }
    }
    return max(mr, mx + ml);
}

void solve()
{
    int n;
    cin >> n;

    if (n == 1) // Edge case for a single node
    {
        cout << "0\n";
        return;
    }

    vii adj(n);
    int x, y;
    for (int i = 1; i < n; i++) // Fix loop to run n-1 times
    {
        cin >> x >> y;
        x--, y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    cout << f(0, -1, 1, 0, adj)-1 << endl;
}

int main()
{
    IOS;
    int tc = 1;
     cin >> tc;
    for (int t = 1; t <= tc; t++)
        solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
//                                       Sk Najir
#ifndef ONLINE_JUDGE
#include "db.hpp"
#else
#define dbg(x)
#define dbg2(x, y)
#define dbg3(x, y, z)
#endif
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);

// pre_define
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

// shortcut type
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;

// Constants
const int MOD = 1e9 + 7;

int f(int i, int pr, bool c, int p, vii &adj)
{
    int mx = max(0, (int)adj[i].size() - p); // Ensure mx is non-negative
    int mr = 0, ml = 0;

    for (auto &j : adj[i])
    {
        if (j == pr)
            continue;
        mr = max(mr, f(j, i, c, 0, adj));
        if (c)
        {
            ml = max(ml, f(j, i, !c, 1, adj));
        }
    }
    return max(mr, mx + ml);
}

void solve()
{
    int n;
    cin >> n;

    if (n == 1) // Edge case for a single node
    {
        cout << "0\n";
        return;
    }

    vii adj(n);
    int x, y;
    for (int i = 1; i < n; i++) // Fix loop to run n-1 times
    {
        cin >> x >> y;
        x--, y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    cout << f(0, -1, 1, 0, adj)-1 << endl;
}

int main()
{
    IOS;
    int tc = 1;
     cin >> tc;
    for (int t = 1; t <= tc; t++)
        solve();
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
//                                       Sk Najir
#ifndef ONLINE_JUDGE
#include "db.hpp"
#else
#define dbg(x)
#define dbg2(x, y)
#define dbg3(x, y, z)
#endif
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);

// pre_define
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

// shortcut type
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;

// Constants
const int MOD = 1e9 + 7;

int f(int i, int pr, bool c, int p, vii &adj)
{
    int mx = max(0, (int)adj[i].size() - p)-c; // Ensure mx is non-negative
    int mr = 0, ml = 0;

    for (auto &j : adj[i])
    {
        if (j == pr)
            continue;
        mr = max(mr, f(j, i, c, 0, adj));
        if (c)
        {
            ml = max(ml, f(j, i, !c, 1, adj));
        }
    }
    return max(mr, mx + ml);
}

void solve()
{
    int n;
    cin >> n;

    if (n == 1) // Edge case for a single node
    {
        cout << "0\n";
        return;
    }

    vii adj(n);
    int x, y;
    for (int i = 1; i < n; i++) // Fix loop to run n-1 times
    {
        cin >> x >> y;
        x--, y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    cout << f(0, -1, 1, 0, adj) << endl;
}

int main()
{
    IOS;
    int tc = 1;
     cin >> tc;
    for (int t = 1; t <= tc; t++)
        solve();
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

#include <string>



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

#define ll long long int

#define int long long 

#define endl "\n"

#define MAX INT_MAX

#define MIN INT_MIN

#define pb push_back



using namespace std;



void solve()

{

    int n, l, r;

    cin >> n >> l >> r;

    

    vector<int> a(n);

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

        cin >> a[i];

    }



    int k = r-l+1;



    int originalSum = accumulate(a.begin()+(l-1), a.begin()+r, 0);



    vector<int> sa = a;

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



    int minPossibleSum = accumulate(sa.begin(), sa.begin()+k, 0);



    cout << min(originalSum, minPossibleSum) << endl;

}



int32_t main()

{

    FAST_IO;

    int t;

    cin >> t;



    while (t--)

        solve();



    return 0;

}



Submission (verdict: Accepted):
#include <bits/stdc++.h>
#include <string>

#define FAST_IO             (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define ll long long int
#define int long long 
#define endl "\n"
#define MAX INT_MAX
#define MIN INT_MIN
#define pb push_back

using namespace std;

void solve()
{
    int n, l, r;
    cin >> n >> l >> r;
    
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }

    vector<int> b = a;
    sort(b.begin()+l-1, b.end());

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

    int sb = 0, sc = 0;
    for (int i=l-1; i<r; i++) {
        sb += b[i];
        sc += c[i];
    } 

    cout << min(sb, sc) << endl;
}

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

    while (t--)
        solve();

    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#include <string>

#define FAST_IO             (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define ll long long int
#define int long long 
#define endl "\n"
#define MAX INT_MAX
#define MIN INT_MIN
#define pb push_back

using namespace std;

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

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

    int k = r-l+1;
    int ans = 0;
    vector<int> :: iterator it;
    for (int i=0; i<k; i++) {
        it = min_element(a.begin(), a.end());
        ans += *it;
        a.erase(it);
    }

    cout << ans << endl;
}

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

    while (t--)
        solve();

    return 0;
}