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

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

#include <functional>

#include <vector>

using namespace std;

#define pb push_back

#define fi first

#define se second

#define mp make_pair

#define endl '\n';

#define sz(x) ((int)(x).size())

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

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

#define char unsigned char



typedef long long ll;

typedef long double ld;



void solve() {

  ll n, l, r;

  cin >> n >> l >> r;

  l--, r--;

  vector<int> a(n);

  for (auto &i : a)

    cin >> i;

  multiset<int, greater<int>> mid;

  multiset<int> right, left;

  ll ans = 0;

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

    mid.insert(a[i]);

    ans += a[i];

  }

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

    left.insert(a[i]);

  }

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

    right.insert(a[i]);

  }

  ll val = 0;

  while (!mid.empty() && !left.empty()) {

    auto m = mid.begin();

    auto l = left.begin();

    if (*m >= *l) {

      val = val - *m + *l;

      mid.erase(m);

      left.erase(l);

    } else {

      break;

    }

  }

  ans = min(ans, ans + val);

  val = 0;

  while (!mid.empty() && !right.empty()) {

    auto m = mid.begin();

    auto r = right.begin();

    if (*m >= *r) {

      val = val - *m + *r;

      mid.erase(m);

      right.erase(r);

    } else {

      break;

    }

  }

  ans = min(ans, ans + val);

  cout << ans << endl;



  return;

}



int main() {

  ios::sync_with_stdio(0);

  cin.tie(0);



  int TET = 1;

  cin >> TET;



  while (TET--) {

    solve();

  }

}



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

#include <functional>

#include <vector>

using namespace std;

#define pb push_back

#define fi first

#define se second

#define mp make_pair

#define endl '\n';

#define sz(x) ((int)(x).size())

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

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

#define char unsigned char



typedef long long ll;

typedef long double ld;



void solve() {

  ll n, l, r;

  cin >> n >> l >> r;

  l--, r--;

  vector<int> a(n);

  for (auto &i : a)

    cin >> i;

  multiset<int, greater<int>> mid;

  multiset<int> right, left;

  ll orig = 0;

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

    mid.insert(a[i]);

    orig += a[i];

  }

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

    left.insert(a[i]);

  }

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

    right.insert(a[i]);

  }

  ll diff1 = 0;

  while (!mid.empty() && !left.empty()) {

    auto m = mid.begin();

    auto l = left.begin();

    if (*m >= *l) {

      diff1 = diff1 - *m + *l;

      mid.erase(m);

      left.erase(l);

    } else {

      break;

    }

  }

  ll ans = min(orig, orig + diff1);

  ll diff2 = 0;

  while (!mid.empty() && !right.empty()) {

    auto m = mid.begin();

    auto r = right.begin();

    if (*m >= *r) {

      diff2 = diff2 - *m + *r;

      mid.erase(m);

      right.erase(r);

    } else {

      break;

    }

  }

  ans = min(ans, orig + diff2);

  cout << ans << endl;



  return;

}



int main() {

  ios::sync_with_stdio(0);

  cin.tie(0);



  int TET = 1;

  cin >> TET;



  while (TET--) {

    solve();

  }

}