Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

#ifdef APPLE
#include <competitive/debug>
#else
#define debug(...) void()
#endif

template<typename T> bool chmax(T &a, const T &b) { return (b > a ? a = b, true : false); }
template<typename T> bool chmin(T &a, const T &b) { return (b < a ? a = b, true : false); }

using i64 = int64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int tt;
  cin >> tt;
  
  while (tt--) {
    int n, l, r;
    cin >> n >> l >> r;

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

    sort(b.begin(), b.end());
    
    map<int, int> rank;
    for (int i = 0; i < n; i++) {
      rank[b[i].second] = i;
    }

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

    vector<int> la, ra;
    for (int i = 0, j = r; i < l && j >= l; i++) {
      if (a[i] < a[j]) {
        la.push_back(a[i]);
        j--;
      }
    }

    for (int i = r+1, j = r; i < n && j >= l; i++) {
      if (a[i] < a[j]) {
        ra.push_back(a[i]);
        j--;
      }
    }

    if (la.size() > ra.size() || accumulate(la.begin(), la.end(), 0LL) < accumulate(ra.begin(), ra.end(), 0LL)) {
      cout << accumulate(la.begin(), la.end(), 0LL) + (r + 1 - la.size() >= l ? accumulate(a.begin() + l, a.begin() + r + 1 - la.size(), 0LL) : 0) << '\n';
    }
    else {
      cout << accumulate(ra.begin(), ra.end(), 0LL) + (r + 1 - ra.size() >= l ? accumulate(a.begin() + l, a.begin() + r + 1 - ra.size(), 0LL) : 0) << '\n';
    }
  }
}

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

using namespace std;



#ifdef APPLE

#include <competitive/debug>

#else

#define debug(...) void()

#endif



template<typename T> bool chmax(T &a, const T &b) { return (b > a ? a = b, true : false); }

template<typename T> bool chmin(T &a, const T &b) { return (b < a ? a = b, true : false); }



using i64 = int64_t;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(nullptr);



  int tt;

  cin >> tt;

  

  while (tt--) {

    int n, l, r;

    cin >> n >> l >> r;



    l--; r--;

    

    vector<int> a(n);

    vector<pair<int, int>> b(n);

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

      cin >> a[i];

      b[i] = {a[i], i};

    }



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

    

    map<int, int> rank;

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

      rank[b[i].second] = i;

    }



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

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

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



    vector<int> la, ra;

    for (int i = 0, j = r; i < l && j >= l; i++) {

      if (a[i] < a[j]) {

        la.push_back(a[i]);

        j--;

      }

    }



    for (int i = r+1, j = r; i < n && j >= l; i++) {

      if (a[i] < a[j]) {

        ra.push_back(a[i]);

        j--;

      }

    }



    cout << min(accumulate(la.begin(), la.end(), 0LL) + (r + 1 - la.size() >= l ? accumulate(a.begin() + l, a.begin() + r + 1 - la.size(), 0LL) : 0),

            accumulate(ra.begin(), ra.end(), 0LL) + (r + 1 - ra.size() >= l ? accumulate(a.begin() + l, a.begin() + r + 1 - ra.size(), 0LL) : 0)) << '\n';

  }

}