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;



#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



template <class T>

using ordered_set =

    __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,

                     __gnu_pbds::tree_order_statistics_node_update>;



#define TRACE(x) cerr << __LINE__ << ": " << #x << " = " << x << endl

#define _ << " _ " <<



template <class T, class U> ostream &operator<<(ostream &o, pair<T, U> x) {

  return o << "(" << x.first << ", " << x.second << ")";

}

template <class> struct is_container : false_type {};

template <class... Ts> struct is_container<vector<Ts...>> : true_type {};

template <class... Ts> struct is_container<map<Ts...>> : true_type {};

template <class... Ts> struct is_container<unordered_map<Ts...>> : true_type {};

template <class... Ts> struct is_container<set<Ts...>> : true_type {};

template <class... Ts> struct is_container<unordered_set<Ts...>> : true_type {};

template <class... Ts> struct is_container<multiset<Ts...>> : true_type {};

template <class... Ts>

struct is_container<unordered_multiset<Ts...>> : true_type {};

template <class T, class = typename enable_if<is_container<T>::value>::type>

ostream &operator<<(ostream &o, T x) {

  int f = 1;

  o << "{";

  for (auto y : x) {

    o << (f ? "" : ", ") << y;

    f = 0;

  }

  return o << "}";

}



typedef long long llint;



const int MAXN = 1e5 + 10;



int t, n, l, r;

int a[MAXN];



void solve() {

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

  --l;

  --r;

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

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



  llint sum = 0;

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

    sum += (llint)a[i];



  sort(a, a + l);

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

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



  llint dl = 0, dr = 0;

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

    if (r - i < l)

      continue;

    if (a[i] < a[r - i])

      dl += (llint)a[r - i] - a[i];

  }



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

    if (r - (i - r - 1) < l)

      continue;

    if (a[i] < a[r - (i - r - 1)])

      dr += (llint)a[r - (i - r - 1)] - a[i];

  }



  printf("%lld\n", sum - max(dl, dr));

}



int main(void) {

  scanf("%d", &t);

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

    TRACE(i + 1);

    solve();

  }

  return 0;

}



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



using namespace std;



#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



template <class T>

using ordered_set =

    __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,

                     __gnu_pbds::tree_order_statistics_node_update>;



#define TRACE(x) cerr << __LINE__ << ": " << #x << " = " << x << endl

#define _ << " _ " <<



template <class T, class U> ostream &operator<<(ostream &o, pair<T, U> x) {

  return o << "(" << x.first << ", " << x.second << ")";

}

template <class> struct is_container : false_type {};

template <class... Ts> struct is_container<vector<Ts...>> : true_type {};

template <class... Ts> struct is_container<map<Ts...>> : true_type {};

template <class... Ts> struct is_container<unordered_map<Ts...>> : true_type {};

template <class... Ts> struct is_container<set<Ts...>> : true_type {};

template <class... Ts> struct is_container<unordered_set<Ts...>> : true_type {};

template <class... Ts> struct is_container<multiset<Ts...>> : true_type {};

template <class... Ts>

struct is_container<unordered_multiset<Ts...>> : true_type {};

template <class T, class = typename enable_if<is_container<T>::value>::type>

ostream &operator<<(ostream &o, T x) {

  int f = 1;

  o << "{";

  for (auto y : x) {

    o << (f ? "" : ", ") << y;

    f = 0;

  }

  return o << "}";

}



typedef long long llint;



const int MAXN = 1e5 + 10;



int t, n, l, r;

int a[MAXN];



void solve() {

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

  --l;

  --r;

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

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



  llint sum = 0;

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

    sum += (llint)a[i];



  vector<int> A, B, C;

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

    if (i < l)

      A.push_back(a[i]);

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

      B.push_back(a[i]);

    if (i > r)

      C.push_back(a[i]);

  }



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

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

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



  reverse(B.begin(), B.end());



  llint dl = 0, dr = 0;

  for (int i = 0; i < (int)min(A.size(), B.size()); ++i)

    if (A[i] < B[i])

      dl += (llint)(B[i] - A[i]);



  for (int i = 0; i < (int)min(C.size(), B.size()); ++i)

    if (C[i] < B[i])

      dl += (llint)(B[i] - C[i]);



  printf("%lld\n", sum - max(dl, dr));

}



int main(void) {

  scanf("%d", &t);

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

    solve();

  }

  return 0;

}