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

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <sstream>

#include <queue>

#include <deque>

#include <bitset>

#include <iterator>

#include <list>

#include <stack>

#include <map>

#include <set>

#include <functional>

#include <numeric>

#include <utility>

#include <limits>

#include <time.h>

#include <math.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <assert.h>

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pll;

typedef vector<ll> vll;

typedef vector<bool> vb;

typedef vector<pair<ll,ll>> vpll;

typedef vector<vector<ll>> vvll;



#define fi first

#define se second

#define pb push_back

#define mod 1000000007



#define f(i,s,e) for( ll i=s; i<e; i++)

#define fa(i,a) for( auto i: a)

#define fe(i,s,e) for( ll i=s; i<=e; i++)

#define fr(i,e,s) for( ll i=e; i>=s; i--)

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

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



#define get(a) cin >> a

#define get2(a,b) cin >> a >> b

#define get3(a,b,c) cin >> a >> b >> c



#define pnl cout << "\n"

#define print(a) cout << a << " "

#define print2(a,b) cout << a << " " << b << " "

#define print3(a,b,c) cout << a << " " << b << " " << c << " "



ll vmax(vll a) { ll mx=a[0]; fa(i,a) mx=max( i, mx); return mx; }

ll vmin(vll a) { ll mi=a[0]; fa(i,a) mi=min( i, mi); return mi; }

ll vsum(vll a) { ll sm=0; fa(i,a) sm+=i; return sm; }



ll add( ll x, ll y) { ll res=x+y; return ( res>mod ? res-mod:res ); }

ll mult( ll x, ll y) { ll res=x*y; return ( res>mod ? res%mod:res ); }

ll sub( ll x, ll y) { ll res=x-y; return ( res<0 ? res+mod:res ); }

ll pow( ll x, ll y) { ll res=1; x%=mod; while(y){ if(y&1) res=mult(res,x); y>>=1; x=mult(x,x);} return res; }



void getv(vll &a) { f(i,0,a.size()) get(a[i]); }

void getvp(vpll &a) { f(i,0,a.size()) get(a[i].fi), get(a[i].se); }

void getvv(vvll &a) { f(i,0,a.size()) f(j,0,a[0].size()) get(a[i][j]); }

void printv(vll a) { fa(i,a) print(i); pnl; }

void printvp(vpll a) { fa(i,a) print2(i.fi, i.se), pnl; }

void printvv(vvll a) { fa(i,a) { fa(j,i) print(j); pnl; }}



void yes() { print("YES"); }

void no() { print("NO"); }



void solve() {

	ll n, l, r; 

    get3( n, l, r);



    vll a(n);

    getv(a);



    vll s1=a, s2=a;

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

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



    ll ans1=0, ans2=0;

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

        ans1+=s1[i], ans2+=s2[i];



    print(min(ans1, ans2)); pnl;

}



int main() {

    ios_base::sync_with_stdio(0);

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



    ll t; get(t);

    while(t--) 

		solve();



    return 0;

}

Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<pair<ll,ll>> vpll;
typedef vector<vector<ll>> vvll;

#define fi first
#define se second
#define pb push_back
#define mod 1000000007

#define f(i,s,e) for( ll i=s; i<e; i++)
#define fa(i,a) for( auto i: a)
#define fe(i,s,e) for( ll i=s; i<=e; i++)
#define fr(i,e,s) for( ll i=e; i>=s; i--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define get(a) cin >> a
#define get2(a,b) cin >> a >> b
#define get3(a,b,c) cin >> a >> b >> c

#define pnl cout << "\n"
#define print(a) cout << a << " "
#define print2(a,b) cout << a << " " << b << " "
#define print3(a,b,c) cout << a << " " << b << " " << c << " "

ll vmax(vll a) { ll mx=a[0]; fa(i,a) mx=max( i, mx); return mx; }
ll vmin(vll a) { ll mi=a[0]; fa(i,a) mi=min( i, mi); return mi; }
ll vsum(vll a) { ll sm=0; fa(i,a) sm+=i; return sm; }

ll add( ll x, ll y) { ll res=x+y; return ( res>mod ? res-mod:res ); }
ll mult( ll x, ll y) { ll res=x*y; return ( res>mod ? res%mod:res ); }
ll sub( ll x, ll y) { ll res=x-y; return ( res<0 ? res+mod:res ); }
ll pow( ll x, ll y) { ll res=1; x%=mod; while(y){ if(y&1) res=mult(res,x); y>>=1; x=mult(x,x);} return res; }

void getv(vll &a) { f(i,0,a.size()) get(a[i]); }
void getvp(vpll &a) { f(i,0,a.size()) get(a[i].fi), get(a[i].se); }
void getvv(vvll &a) { f(i,0,a.size()) f(j,0,a[0].size()) get(a[i][j]); }
void printv(vll a) { fa(i,a) print(i); pnl; }
void printvp(vpll a) { fa(i,a) print2(i.fi, i.se), pnl; }
void printvv(vvll a) { fa(i,a) { fa(j,i) print(j); pnl; }}

void yes() { print("YES"); }
void no() { print("NO"); }

void solve() {
	ll n, l, r; 
    get3( n, l, r);

    vll a(n);
    getv(a);

    vll s1=a, s2=a;
    sort( s1.begin(), s1.begin()+r);
    sort( s2.begin()+l-1, s2.end());

    ll ans1=0, ans2=0, ans=0;
    for( ll i=0; i<r-l+1; i++) 
        ans1+=s1[i], ans2+=s2[i], ans+=a[l-1+i];

    if( ans!=min( ans1, ans2))
        print(min(ans1, ans2)); 
    else {
        sort( a.begin(), a.end());
        print( ans-a[r-l-1]+a[r-l] );
    }
    pnl;
}

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

    ll t; get(t);
    while(t--) 
		solve();

    return 0;
}