ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Compilation error):
// #ifndef ONLINE_JUDGE
// #include "debug/debud.h"
// #endif
// #ifdef ONLINE_JUDGE
// #define dbg(x)
// #define dbgs(...)
// #endif

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr)
#define ll long long
#define loop(i, a, b) for (int i = a; i < b; i += 1)
#define rloop(i, a, b) for (int i = b - 1; i >= a; i -= 1)
#define yn(f) (f) ? cout << "YES\n" : cout << "NO\n"
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define cmax(a, b) a = max(a, b)
#define cmin(a, b) a = min(a, b)
#define in(...)      \
    int __VA_ARGS__; \
    input(__VA_ARGS__);
#define endl '\n'
const long long int modu = 1000000007;
template <typename... Args>
void input(Args&... args) {
    ((cin >> args), ...);
}
template <typename T1, typename T2>
istream& operator>>(istream& istream, pair<T1, T2>& p) {
    return (istream >> p.first >> p.second);
}
template <typename T>
istream& operator>>(istream& istream, vector<T>& v) {
    for (auto& it : v) cin >> it;
    return istream;
}
template <typename T>
ostream& operator<<(ostream& ostream, const vector<T>& c) {
    for (auto& it : c) ostream << it << " ";
    return ostream;
}
#define int ll

void solve() {
    string a, b, c;
    cin >> a >> b >> c;

    int ans = 1e9;

    auto f = [&](int i, int j, string& ss) {
        if (i + j == c.size()) {
            int t = 0;
            for (int k = 0; k < c.size(); ++k) {
                t += (ss[k] != c[k]);
            }
            ans = min(ans, t);
            return;
        }

        if (i < a.size()) {
            ss.push_back(a[i]);
            f(i + 1, j, ss);
            ss.pop_back();
        }
        if (j < b.size()) {
            ss.push_back(b[j]);
            f(i, j + 1, ss);
            ss.pop_back();
        }
    };

    string ss = "";
    f(0, 0, ss);

    cout << ans << endl;
}

signed main() {
    fast_io;
    int t = 1;
    cin >> t;
    for (int i = 1; i < t + 1; i++) {
        // cerr << "----- TC " << i << " -----" << endl;
        solve();
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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

string solve(){
	int n;
	cin>>n;
	vector<int> a;
	for(int i = 0;i<n;i++){
		int temp;
		cin>>temp;
		a.push_back(temp);
	}
	for(int i = 0;i<n-2;i++){
		if(a[i]>a[i+1]) return "NO";
		else {
			if(a[i+1]-a[i]>a[i+2]) return "NO";
		}
		i++;
	}
	return "YES";
}

int main(){
	int t;
	cin>>t;
	while(t--){
		string ans = solve();
		cout<<ans<<endl;
	}
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

string solve(){
	int n;
	cin>>n;
	vector<int> a;
	for(int i = 0;i<n;i++){
		int temp;
		cin>>temp;
		a.push_back(temp);
	}
	for(int i = 0;i<n-2;i++){
		if(a[i]>a[i+1]) return "NO";
		else {
			if(a[i+1]-a[i]>a[i+2]) return "NO";
		}
		i++;
	}
	return "YES";
}

int main(){
	int t;
	cin>>t;
	while(t--){
		string ans = solve();
		cout<<ans<<endl;
	}
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> v(n);
        for(int i=0;i<n;i++){
            cin>>v[i];
        }
        bool b = true;
        for(int i=1;i<n-1;i++){
            if(v[i]-v[i-1]>0 && v[i]-v[i-1]<=v[i+1]){
                v[i] = v[i]-v[i-1];
                v[i-1] = 0;
            }
            else{
                b = false;
                break;
            }
        }
        if(n==2){
            if(v[1]<v[0]){
                b = false;
            }
        }
        if(b){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> v(n);
        for(int i=0;i<n;i++){
            cin>>v[i];
        }
        bool b = true;
        for(int i=1;i<n-1;i++){
            if(v[i]-v[i-1]>0 && v[i]-v[i-1]<=v[i+1]){
                v[i] = v[i]-v[i-1];
                v[i-1] = 0;
            }
            else{
                b = false;
                break;
            }
        }
        if(n==2){
            if(v[1]<v[0]){
                b = false;
            }
        }
        if(b){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> v(n);
        for(int i=0;i<n;i++){
            cin>>v[i];
        }
        bool b = true;
        for(int i=1;i<n-1;i++){
            if(v[i]-v[i-1]>=0 && v[i]-v[i-1]<=v[i+1]){
                v[i] = v[i]-v[i-1];
                v[i-1] = 0;
            }
            else{
                b = false;
                break;
            }
        }
        if(n==2){
            if(v[1]<v[0]){
                b = false;
            }
        }
        if(b){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

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

void solve() {
	int n, k; cin >> n >> k;
	vector<int> a(n); map<int, int> mp;
	for (int i = 0; i < n; ++i) {
		cin >> a[i]; mp[a[i]]++;
	}
	vector<int> b;
	for (auto e: mp) {
		b.push_back(e.second);
	}
	sort(b.begin(), b.end());
	for (int i = 0; i < n; ++i) {
		k -= b[i];
		if (k < 0) {
			cout << b.size() - i << endl;
			return;
		}
	}
	cout << 1 << endl;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
	int n, k; cin >> n >> k;
	vector<int> a(n); map<int, int> mp;
	for (int i = 0; i < n; ++i) {
		cin >> a[i]; mp[a[i]]++;
	}
	vector<int> b;
	for (auto e: mp) {
		b.push_back(e.second);
	}
	sort(b.begin(), b.end());
	for (int i = 0; i < n - 1; ++i) {
		if (b[i] > k) {
			cout << b.size() - i << endl;
			return;
		}
		k -= b[i];
	}
	cout << 1 << endl;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

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

void solve() {
	int n, k; cin >> n >> k;
	vector<int> a(n); map<int, int> mp;
	for (int i = 0; i < n; ++i) {
		cin >> a[i]; mp[a[i]]++;
	}
	vector<int> b;
	for (auto e: mp) {
		b.push_back(e.second);
	}
	sort(b.begin(), b.end());
	for (int i = 0; i < n - 1; ++i) {
		if (b[i] > k) {
			cout << b.size() - i << endl;
			return;
		}
		k -= b[i];
	}
	cout << 1 << endl;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
	int n, k; cin >> n >> k;
	vector<int> a(n); map<int, int> mp;
	for (int i = 0; i < n; ++i) {
		cin >> a[i]; mp[a[i]]++;
	}
	vector<int> b;
	for (auto e: mp) {
		b.push_back(e.second);
	}
	sort(b.begin(), b.end());
	for (int i = 0; i < b.size() - 1; ++i) {
		if (b[i] > k) {
			cout << b.size() - i << endl;
			return;
		}
		k -= b[i];
	}
	cout << 1 << endl;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
	int n, k; cin >> n >> k;
	vector<int> a(n); map<int, int> mp;
	for (int i = 0; i < n; ++i) {
		cin >> a[i]; mp[a[i]]++;
	}
	vector<int> b;
	for (auto e: mp) {
		b.push_back(e.second);
	}
	sort(b.begin(), b.end());
	for (int i = 0; i < n; ++i) {
		k -= b[i];
		if (k < 0) {
			cout << b.size() - i << endl;
			return;
		}
	}
	cout << 1 << endl;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <algorithm>
#include <stack>
#include <set>
#include <list>
#include <map>
#include <cstring>
#include <iterator>
#define ll long long
#define MOD 1000000007 
using namespace std;
vector<int>sieve(int n){
    vector<int>p;
    vector<int>isprime(n+1, 1);
    isprime[0] = isprime[1] = 0;
    for (int i = 2; i<=n; i++){
        if (isprime[i]){
            for (int j = 2*i; j<=n; j+=i){
                isprime[j] = 0;
            }
        }
    }
    for (int i = 1; i<=n; i++){
        if (isprime[i]){
            p.push_back(i);
        }
    }
    return p;
}
//---------------------------------------------------------------------------
// bool check(int k, vector<int>d, vector<int>a){

// }

void solve(){
    int n;
    cin>>n;
    vector<vector<int>>adj(n);
    map<int,int>ed;
    for (int i = 0; i<n-1; i++){
        int u, v;
        cin>>u>>v;
        u--;
        v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 0; i<n; i++){
        ed[i] = adj[i].size();
    }
    int edmax = 0;
    int maxver = 0;
    for (auto i:ed){
        if (i.second > edmax){
            edmax = i.second;
            maxver = i.first;
        }
    }
    for (int i:adj[maxver]){
        ed[i] -= 1;
    }
    int edmax1 = 0;
    int maxver1 = 0;
    for (auto i:ed){
        if (i.first != maxver && i.second > edmax1){
            edmax1 = i.second;
            maxver1 = i.first;
        }
    }
    cout<<edmax + edmax1 - 1<<endl;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    // solve();
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define pb push_back
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define f first
#define s second

using namespace std;

void solve()
{
    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        int q = 0;
        int mx = s[i] - 48;
        for (int j = 1; i + j < s.size(); j++)
        {
            int x = s[i + j] - 48;
            x -= j;
            if (x > mx)
            {
                q = j;
                mx = x;
            }
        }

        for (int j = i + q; j > i; j--)
            swap(s[j], s[j - 1]);

        s[i] -= q;
    }

    cout << s << "\n";
}

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

    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define pb push_back
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define f first
#define s second

using namespace std;

void solve()
{
    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        int q = 0;
        int mx = s[i] - 48;
        for (int j = 1; i + j < s.size() && j < i + 10; j++)
        {
            int x = s[i + j] - 48;
            x -= j;
            if (x > mx)
            {
                q = j;
                mx = x;
            }
        }

        for (int j = i + q; j > i; j--)
            swap(s[j], s[j - 1]);

        s[i] -= q;
    }

    cout << s << "\n";
}

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

    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define pb push_back
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define f first
#define s second

using namespace std;

void solve()
{
    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        int q = 0;
        int mx = s[i] - 48;
        for (int j = 1; i + j < s.size() && j < i + 10; j++)
        {
            int x = s[i + j] - 48;
            x -= j;
            if (x > mx)
            {
                q = j;
                mx = x;
            }
        }

        for (int j = i + q; j > i; j--)
            swap(s[j], s[j - 1]);

        s[i] -= q;
    }

    cout << s << "\n";
}

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

    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}


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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define pb push_back
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define f first
#define s second

using namespace std;

void solve()
{
    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        int q = 0;
        int mx = s[i] - 48;
        for (int j = 1; i + j < s.size() && j < 10; j++)
        {
            int x = s[i + j] - 48;
            x -= j;
            if (x > mx)
            {
                q = j;
                mx = x;
            }
        }

        for (int j = i + q; j > i; j--)
            swap(s[j], s[j - 1]);

        s[i] -= q;
    }

    cout << s << "\n";
}

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

    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define pb push_back
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define f first
#define s second

using namespace std;

void solve()
{
    string s;

    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        int q = 0;
        int mx = s[i] - 48;
        for (int j = 1; i + j < s.size(); j++)
        {
            int x = s[i + j] - 48;
            x -= j;
            if (x > mx)
            {
                q = j;
                mx = x;
            }
        }

        for (int j = i + q; j > i; j--)
            swap(s[j], s[j - 1]);

        s[i] -= q;
    }

    cout << s << "\n";
}

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

    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 6):
//DIGITAL STRING TRANSFORMATION

//AUTHOR : PiyushShrey



#include <bits/stdc++.h>

using namespace std;



void solve(){

string s;

cin>>s;

int n=s.length();

for(int i=0;i<s.size();i++){

int k=min(i+10,n-1-i);

int j=i+1;

int best = s[i] - '0', pos = i;

while(k--){

if(s[j]!='0'){

if(s[j] != '0'){

int x = s[j] - '0' - (j - i);

if (x > best) {

best = x;

pos = j;

}

}

}

j++;

}

while(pos>i){

swap(s[pos], s[pos - 1]);

pos--;

}



s[i] = char(best + '0');

}

cout<<s<<endl;

}





int main()

{

int t;

cin>>t;

while(t--)solve();

return 0;

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
//DIGITAL STRING TRANSFORMATION

//AUTHOR : PiyushShrey



#include <bits/stdc++.h>

using namespace std;



void solve(){

string s;

cin>>s;

int n=s.length();

for(int i=0;i<s.size();i++){

int k=min(i+10,n);

int j=i+1;

int best = s[i] - '0', pos = i;

while(k--){

if(s[j]!='0'){

if(s[j] != '0'){

int x = s[j] - '0' - (j - i);

if (x > best) {

best = x;

pos = j;

}

}

}

j++;

}

while(pos>i){

swap(s[pos], s[pos - 1]);

pos--;

}



s[i] = char(best + '0');

}

cout<<s<<endl;

}





int main()

{

int t;

cin>>t;

while(t--)solve();

return 0;

}

Submission (verdict: Accepted):
//DIGITAL STRING TRANSFORMATION

//AUTHOR : PiyushShrey



#include <bits/stdc++.h>

using namespace std;



void solve() {

string s;

cin >> s;

int n = s.size();



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

int best = s[i] - '0', pos = i;



for (int j = i + 1; j < min(i + 10, n); j++) {

int x = s[j] - '0' - (j - i);

if (x > best) {

best = x;

pos = j;

}

}



while (pos > i) {

swap(s[pos], s[pos - 1]);

pos--;

}



s[i] = char(best + '0');

}



cout << s << endl;

}





int main()

{

int t;

cin>>t;

while(t--)solve();

return 0;

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 6):
//DIGITAL STRING TRANSFORMATION

//AUTHOR : PiyushShrey



#include <bits/stdc++.h>

using namespace std;



void solve(){

string s;

cin>>s;

int n=s.length();

for(int i=0;i<s.size();i++){

int k=min(i+10,n-1-i);

int j=i+1;

int best = s[i] - '0', pos = i;

while(k--){

if(s[j]!='0'){

if(s[j] != '0'){

int x = s[j] - '0' - (j - i);

if (x > best) {

best = x;

pos = j;

}

}

}

j++;

}

while(pos>i){

swap(s[pos], s[pos - 1]);

pos--;

}



s[i] = char(best + '0');

}

cout<<s<<endl;

}





int main()

{

int t;

cin>>t;

while(t--)solve();

return 0;

}

Submission (verdict: Wrong answer on test 1):
//DIGITAL STRING TRANSFORMATION

//AUTHOR : PiyushShrey



#include <bits/stdc++.h>

using namespace std;



void solve(){

string s;

cin>>s;

int n=s.length();

for(int i=0;i<s.size();i++){

int k=min(i+10,n);

int j=i+1;

int best = s[i] - '0', pos = i;

while(k--){

if(s[j]!='0'){

if(s[j] != '0'){

int x = s[j] - '0' - (j - i);

if (x > best) {

best = x;

pos = j;

}

}

}

j++;

}

while(pos>i){

swap(s[pos], s[pos - 1]);

pos--;

}



s[i] = char(best + '0');

}

cout<<s<<endl;

}





int main()

{

int t;

cin>>t;

while(t--)solve();

return 0;

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


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int M=1e6+5;
int n,x,y,t,a[M],b[M],sum,ans;
bool cmp(int x,int y)
{
	return x>y;
}
signed main()
{
	cin>>t;
	while(t--)
	{
		sum=ans=0;
		int x,y;
		cin>>n>>x>>y;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			b[i]=a[i];
		}
		sort(b+1,b+x);
		sort(b+x,b+y+1,cmp);
		sort(b+y+1,b+n+1);
		for(int i=x;i<=y;i++)
		{
			sum+=b[i];
			ans=sum;
		}
		for(int i=1;i<=x;i++)
		{
			if(b[i]>b[x+i-1]||i==x)
			{
				if(i==1)
					break;
				else
				{
					for(int j=x;j<x+i-1;j++)
						sum+=b[j-x+1]-b[j];
				}
				break;
			}
		}
		for(int i=y+1;i<=n+1;i++)
		{
			if(b[i]>b[x+i-y-1]||i==n+1)
			{
				if(i==y+1)
					break;
				else
				{
					for(int j=x;j<x+i-y-1;j++)
						ans+=b[j+y-x+1]-b[j];
				}
				break;
			}
		}
//		cout<<sum<<" "<<ans<<endl;
		cout<<min(ans,sum)<<endl;
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int M=1e6+5;
int n,x,y,t,a[M],b[M],sum,ans;
bool cmp(int x,int y)
{
	return x>y;
}
signed main()
{
	cin>>t;
	while(t--)
	{
		sum=ans=0;
		int x,y;
		cin>>n>>x>>y;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			b[i]=a[i];
		}
		sort(b+1,b+x);
		sort(b+x,b+y+1,cmp);
		sort(b+y+1,b+n+1);
		for(int i=x;i<=y;i++)
		{
			sum+=b[i];
			ans=sum;
		}
		for(int i=1;i<=x;i++)
		{
			if(b[i]>b[x+i-1]||i==x)
			{
				if(i==1)
					break;
				else
				{
					int tt1=0,tt2=0;
					for(int j=1;j<i;j++)
						tt1+=b[j];
					for(int j=x;j<x+i-1;j++)
						tt2+=b[j];
					sum+=tt1-tt2;
				}
				break;
			}
		}
		for(int i=y+1;i<=n+1;i++)
		{
			if(b[i]>b[x+i-y-1]||i==n+1)
			{
				if(i==y+1)
					break;
				else
				{
					int tt1=0,tt2=0;
					for(int j=y+1;j<i;j++)
						tt1+=b[j];
					for(int j=x;j<i-y+x-1;j++)
						tt2+=b[j];
					ans+=tt1-tt2;
				}
				break;
			}
		}
//		cout<<sum<<" "<<ans<<endl;
		cout<<min(ans,sum)<<endl;
	}
	return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int M=1e6+5;
int n,x,y,t,a[M],b[M],sum,ans;
signed main()
{
	cin>>t;
	while(t--)
	{
		sum=ans=0;
		int x,y;
		cin>>n>>x>>y;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			b[i]=a[i];
		}
		sort(a+1,a+y+1);
		sort(b+x,b+n+1);
		for(int j=1;j<=y-x+1;j++)
			sum+=a[j];
		for(int j=x;j<=y;j++)
			ans+=b[j];
		cout<<min(ans,sum)<<endl;
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int M=1e6+5;
int n,x,y,t,a[M],b[M],sum,ans;
bool cmp(int x,int y)
{
	return x>y;
}
signed main()
{
	cin>>t;
	while(t--)
	{
		sum=ans=0;
		int x,y;
		cin>>n>>x>>y;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			b[i]=a[i];
		}
		sort(b+1,b+x);
		sort(b+x,b+y+1,cmp);
		sort(b+y+1,b+n+1);
		for(int i=x;i<=y;i++)
		{
			sum+=b[i];
			ans=sum;
		}
		for(int i=1;i<=x;i++)
		{
			if(b[i]>b[x+i-1]||i==x)
			{
				if(i==1)
					break;
				else
				{
					for(int j=x;j<x+i-1;j++)
						sum+=b[j-x+1]-b[j];
				}
				break;
			}
		}
		for(int i=y+1;i<=n+1;i++)
		{
			if(b[i]>b[x+i-y-1]||i==n+1)
			{
				if(i==y+1)
					break;
				else
				{
					for(int j=x;j<x+i-y-1;j++)
						ans+=b[j+y-x+1]-b[j];
				}
				break;
			}
		}
//		cout<<sum<<" "<<ans<<endl;
		cout<<min(ans,sum)<<endl;
	}
	return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int M=1e6+5;
int n,x,y,t,a[M],b[M],sum,ans;
bool cmp(int x,int y)
{
	return x>y;
}
signed main()
{
	cin>>t;
	while(t--)
	{
		sum=ans=0;
		int x,y;
		cin>>n>>x>>y;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			b[i]=a[i];
		}
		sort(b+1,b+x);
		sort(b+x,b+y+1,cmp);
		sort(b+y+1,b+n+1);
		for(int i=x;i<=y;i++)
		{
			sum+=b[i];
			ans=sum;
		}
		for(int i=1;i<=x;i++)
		{
			if(b[i]>b[x+i-1]||i==x)
			{
				if(i==1)
					break;
				else
				{
					int tt1=0,tt2=0;
					for(int j=1;j<i;j++)
						tt1+=b[j];
					for(int j=x;j<x+i-1;j++)
						tt2+=b[j];
					sum+=tt1-tt2;
				}
				break;
			}
		}
		for(int i=y+1;i<=n+1;i++)
		{
			if(b[i]>b[x+i-y-1]||i==n+1)
			{
				if(i==y+1)
					break;
				else
				{
					int tt1=0,tt2=0;
					for(int j=y+1;j<i;j++)
						tt1+=b[j];
					for(int j=x;j<i-y+x-1;j++)
						tt2+=b[j];
					ans+=tt1-tt2;
				}
				break;
			}
		}
//		cout<<sum<<" "<<ans<<endl;
		cout<<min(ans,sum)<<endl;
	}
	return 0;
}