Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

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 <typename T, typename Cmp = less<T>>

using ordered_set =

    __gnu_pbds::tree<T, __gnu_pbds::null_type, Cmp, __gnu_pbds::rb_tree_tag,

                     __gnu_pbds::tree_order_statistics_node_update>;



typedef int64_t i64;



#ifdef DEBUG

static constexpr size_t N = 20;



#include "debug.h"

#else

static constexpr size_t N = 2e5 + 5;

#endif  // DEBUG



static constexpr i64 MOD = 1e9 + 7, INF = 0x7fffffff7fffffff;

static constexpr i64 MOD2 = 998244353;



static int arr[N];



int main() {

#ifndef DEBUG

  std::ios::sync_with_stdio(false);

  std::cin.tie(nullptr);

  std::cout.tie(nullptr);

#endif

  int T = 1;

  cin >> T;

  while (T-- > 0) {

    int n, l, r;

    cin >> n >> l >> r;

    i64 s = 0;



    priority_queue<int> pq, pqr;

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

      cin >> arr[i];

      if (i >= l && r >= i) {

        s += arr[i];

        pq.push(arr[i]);

      }

    }

    pqr = pq;

    i64 ans = s;

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

      if (arr[i] < pq.top()) {

        s -= pq.top();

        pq.pop();

        s += arr[i];

        ans = min(ans, s);

        pq.push(arr[i]);

      }

    }



    pq = pqr;

    for (int i = l - 1; i > 0; i--) {

      if (arr[i] < pq.top()) {

        s -= pq.top();

        pq.pop();

        s += arr[i];

        ans = min(ans, s);

        pq.push(arr[i]);

      }

    }



    println("{}", ans);

  }



  return 0;

}



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



using namespace std;

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



template <typename T, typename Cmp = less<T>>

using ordered_set =

    __gnu_pbds::tree<T, __gnu_pbds::null_type, Cmp, __gnu_pbds::rb_tree_tag,

                     __gnu_pbds::tree_order_statistics_node_update>;



typedef int64_t i64;



#ifdef DEBUG

static constexpr size_t N = 20;



#include "debug.h"

#else

static constexpr size_t N = 2e5 + 5;

#endif  // DEBUG



static constexpr i64 MOD = 1e9 + 7, INF = 0x7fffffff7fffffff;

static constexpr i64 MOD2 = 998244353;



static int arr[N];



int main() {

#ifndef DEBUG

  std::ios::sync_with_stdio(false);

  std::cin.tie(nullptr);

  std::cout.tie(nullptr);

#endif

  int T = 1;

  cin >> T;

  while (T-- > 0) {

    int n, l, r;

    cin >> n >> l >> r;

    i64 s = 0, bs = 0;



    priority_queue<i64> pq, pqr;

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

      cin >> arr[i];

      if (i >= l && r >= i) {

        s += arr[i];

        pq.push(arr[i]);

      }

    }

    bs = s;

    pqr = pq;

    i64 ans = s;

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

      if (arr[i] < pq.top()) {

        s -= pq.top();

        pq.pop();

        s += arr[i];

        ans = min(ans, s);

        pq.push(arr[i]);

      }

    }

    s = bs;

    pq = pqr;

    for (int i = l - 1; i > 0; i--) {

      if (arr[i] < pq.top()) {

        s -= pq.top();

        pq.pop();

        s += arr[i];

        ans = min(ans, s);

        pq.push(arr[i]);

      }

    }



    println("{}", ans);

  }



  return 0;

}