ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 6):
#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t);

    while(t--)
    {
        char s[20001];
        scanf("%s", s);

        for(int i = 0; s[i] != '\0'; i++)
        {
            if(s[i + 1] - s[i] > 1)
            {
                s[i + 1]--;
                s[i] ^= s[i + 1];
                s[i + 1] ^= s[i];
                s[i] ^= s[i + 1];
                i = -1;
            }
        }
        puts(s);
    }

    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pl pair<ll,ll>
#define ml map<ll,ll>
#define fr first
#define sc second
#define pb push_back
ll idx,cnt,n,m,in[200005];
pl pr[200005];
/*/ ------------------------------------------------///
//  $$ - - - * * * - - - * * * - - - * * * - - - $$

  ______  _______  _____  __   __  _______  __   _
 |_____/  |_____|    |      \_/    |_____|  | \  |
 |    \_  |     |  __|__     |     |     |  |  \_|


//  $$ - - - * * * - - - * * * - - - * * * - - - $$\
// ------------------------------------------------*///
ll mx=1e6+7,md=1e9+7,bs=29; string s;
ll fnd(ll x) {return (in[x]==x)?x:in[x]=fnd(in[x]);}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1,x=1,i,j,tc=1;  cin>>t; 
    while(t--){ cnt=0; ml mp; map<pl,ll> mp1;
    ll i,n1,k=0,j=0,ct=0,x=0,y=0,q=1,z=0;
    cin>>n; pl pr1[n-1];
    for(i=1;i<=n;i++) pr[i].fr=0,pr[i].sc=i,in[i]=i;
    for(i=0;i<n-1;i++){
        cin>>x>>y; if(x>y) swap(x,y);
        pr[x].fr++,pr[y].fr++;
        pr1[i]={x,y}; mp1[{x,y}]=1;}
    sort(pr+1,pr+1+n); set<ll> st;
    mp[pr[n].sc]=1,x=n-1; 
while(pr[x].fr==pr[n-1].fr&&x>0&&mp1[{min(pr[x].sc,pr[n].sc),max(pr[x].sc,pr[n].sc)}]) x--;
    if(pr[x].fr==pr[n-1].fr) mp[pr[x].sc]=1; else mp[pr[n-1].sc]=1;
    //cout<<pr[n].sc<<" "<<pr[x].sc<<'\n';
    for(i=0;i<n-1;i++){ x=pr1[i].fr,y=pr1[i].sc;
    if(mp[x]) {in[x]=-1; if(mp[y]) in[y]=-1;
    continue;}
    if(mp[y]) {in[y]=-1; if(mp[x]) in[x]=-1; continue;}
    in[fnd(x)]=fnd(y); }
    for(i=1;i<=n;i++) {if(mp[i]) continue; st.insert(fnd(i));}
    cout<<st.size()<<'\n';
}}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

int main () {

    int t;
    cin>>t;

    while(t--) {
        string s;
        cin>>s;

        int i=s.length()-1;

        while(i!=0) {
            if (int(s[i])== 0) {
                i--;
                continue;
            }
            int temp=int (s[i])-1;
            if (temp > s[i-1]) {
                s[i]=s[i-1];
                s[i-1]=char(temp);
                i=s.length()-1;
            } else {
                i--;
            }
        }

        cout<<s<<endl;



    }




    return 0;
}

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

int main () {

    int t;
    cin>>t;

    while(t--) {
        string s;
        cin>>s;

        int i=s.length()-1;

        while(i!=0) {
            if (s[i]== 0) {
                i--;
                continue;
            }
            int temp=s[i]-1;
            if (temp > s[i-1]) {
                s[i]=s[i-1];
                s[i-1]=temp;
              if (i!=s.length()-1)  i=i+1;
            } else {
                i--;
            }
        }

        cout<<s<<endl;



    }




    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>
using namespace std;

int main () {

    int t;
    cin>>t;

    while(t--) {
        string s;
        cin>>s;

        int i=s.length()-1;

        while(i!=0) {
            if (int(s[i])== 0) {
                i--;
            }
            int temp=int (s[i])-1;
            if (temp > s[i-1]) {
                s[i]=s[i-1];
                s[i-1]=char(temp);
                i=s.length()-1;
            } else {
                i--;
            }
        }

        cout<<s<<endl;



    }




    return 0;
}

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

int main () {

    int t;
    cin>>t;

    while(t--) {
        string s;
        cin>>s;

        int i=s.length()-1;

        while(i!=0) {
            if (int(s[i])== 0) {
                i--;
                continue;
            }
            int temp=int (s[i])-1;
            if (temp > s[i-1]) {
                s[i]=s[i-1];
                s[i-1]=char(temp);
                i=s.length()-1;
            } else {
                i--;
            }
        }

        cout<<s<<endl;



    }




    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>
using namespace std;

int main () {

    int t;
    cin>>t;

    while(t--) {
        string s;
        cin>>s;

        int i=s.length()-1;

        while(i!=0) {
            if (int(s[i])== 0) {
                i--;
            }
            int temp=int (s[i])-1;
            if (temp > s[i-1]) {
                s[i]=s[i-1];
                s[i-1]=char(temp);
                i=s.length()-1;
            } else {
                i--;
            }
        }

        cout<<s<<endl;



    }




    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
const int N = 1e7 + 5;
const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];

        if (n == 1) {
            cout << a[0] << endl;
            continue;
        }

        ll ans = accumulate(all(a) ,0ll);
        while (a.size()>1) {
            vector<int> kk;
            for (int i = 1; i < a.size(); i++) {
                kk.push_back(a[i] - a[i - 1]); 
            }
            ll ff = accumulate(all(kk) , 0ll);
            ans = max(ans ,abs(ff));
            a = kk;
        }
        cout << ans << endl;
    }
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
const int N = 1e7 + 5;
const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<ll> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];

        if (n == 1) {
            cout << a[0] << endl;
            continue;
        }

        ll ans = accumulate(all(a) ,0ll);
        while (a.size()>1) {
            vector<ll> kk;
            for (int i = 1; i < a.size(); i++) {
                kk.push_back(a[i] - a[i - 1]); 
            }
            ll ff = accumulate(all(kk) , 0ll);
            ans = max(ans ,abs(ff));
            a = kk;
        }
        cout << ans << endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
const int N = 1e7 + 5;
const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];

        if (n == 1) {
            cout << a[0] << endl;
            continue;
        }

        ll mx = 0;
        vector<int> temp = a;

        while (temp.size() >=1) {
            ll sum1 = accumulate(all(temp), 0ll);
            
            vector<int> rev_temp = temp;  
            reverse(all(rev_temp));
            ll sum2 = accumulate(all(rev_temp), 0ll);
            
            mx = max({mx, abs(sum1), abs(sum2)});

            vector<int> kk;
            for (int i = 1; i < temp.size(); i++) {
                kk.push_back(temp[i] - temp[i - 1]); 
            }
            temp = kk;
        }
        cout << mx << endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
const int N = 1e7 + 5;
const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];

        if (n == 1) {
            cout << a[0] << endl;
            continue;
        }

        ll mx = 0;
        vector<int> temp = a;

        while (temp.size() >=1) {
            ll sum1 = accumulate(all(temp), 0ll);
            
            vector<int> rev_temp = temp;  
            reverse(all(rev_temp));
            ll sum2 = accumulate(all(rev_temp), 0ll);
            
            mx = max({mx, abs(sum1), abs(sum2)});

            vector<int> kk;
            for (int i = 1; i < temp.size(); i++) {
                kk.push_back(temp[i] - temp[i - 1]); 
            }
            temp = kk;
        }
        cout << mx << endl;
    }
    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
const int N = 1e7 + 5;
const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];

        if (n == 1) {
            cout << a[0] << endl;
            continue;
        }

        ll ans = accumulate(all(a) ,0ll);
        while (a.size()>1) {
            vector<int> kk;
            for (int i = 1; i < a.size(); i++) {
                kk.push_back(a[i] - a[i - 1]); 
            }
            ll ff = accumulate(all(kk) , 0ll);
            ans = max(ans ,abs(ff));
            a = kk;
        }
        cout << ans << endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


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> a(n);
   for(int i=0;i<n;i++){
   cin>>a[i];
   }

   long long sum=0,current=-1e10;
   int sz=n;

   for(int i=0;i<n;i++){
     sum=0;
    for(int j=0;j<sz;j++){
    sum+=a[j];
    }
    if(i==0){
    current=max(sum,current);
    }else{
    current=max(current,max(sum,-sum));
    }
     for(int j=0;j<sz;j++){
      a[j]=a[j+1]-a[j];
      }
     sz--;
     }
   

    cout<<current<<endl;
    }

   }
Problem: 2062C - Cirno and Operations
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> a(n);
   for(int i=0;i<n;i++){
   cin>>a[i];
   }

   long long sum=0,current=-1e10;
   int sz=n;

   for(int i=0;i<n;i++){
     sum=0;
    for(int j=0;j<sz;j++){
    sum+=a[j];
    }
    if(i==0){
    current=max(sum,current);
    }else{
    current=max(current,max(sum,-sum));
    }
     for(int j=0;j<sz;j++){
      a[j]=a[j+1]-a[j];
      }
     sz--;
     }
   

    cout<<current<<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> a(n);
   for(int i=0;i<n;i++){
   cin>>a[i];
   }

   long long sum=0,current=-1e18;
   int sz=n;

   for(int i=0;i<n;i++){
     sum=0;
    for(int j=0;j<sz;j++){
    sum+=a[j];
    }
    if(i==0){
    current=max(sum,current);
    }else{
    current=max(current,max(sum,-sum));
    }
     for(int j=0;j<sz;j++){
      a[j]=a[j+1]-a[j];
      }
     sz--;
     }
   

    cout<<current<<endl;
    }

   }
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

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

   int main(){
   int t;cin>>t;

   while(t--){
   int n;cin>>n;

   vector<int> a(n);
   for(int i=0;i<n;i++){
   cin>>a[i];
   }

   long long sum=0,current=-1e18;
   int sz=n;

   for(int i=0;i<n;i++){
     sum=0;
    for(int j=0;j<sz;j++){
    sum+=a[j];
    }
    if(i==0){
    current=max(sum,current);
    }else{
    current=max(current,max(sum,-sum));
    }
     for(int j=0;j<sz-2;j++){
      a[j]=a[j+1]-a[j];
      }
     sz--;
     }
   

    cout<<current<<endl;
    }

   }

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

   int main(){
   int t;cin>>t;

   while(t--){
   int n;cin>>n;

   vector<long long> a(n);
   for(int i=0;i<n;i++){
   cin>>a[i];
   }

   long long sum=0,current=-1e18;
   int sz=n;

   for(int i=0;i<n;i++){
     sum=0;
    for(int j=0;j<sz;j++){
    sum+=a[j];
    }
    if(i==0){
    current=max(sum,current);
    }else{
    current=max(current,max(sum,-sum));
    }
     for(int j=0;j<sz-1;j++){
      a[j]=a[j+1]-a[j];
      }
     sz--;
     }
   

    cout<<current<<endl;
    }

   }
Problem: 2062C - Cirno and Operations
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> a(n);
   for(int i=0;i<n;i++){
   cin>>a[i];
   }

   long long sum=0,current=-1e18;
   int sz=n;

   for(int i=0;i<n;i++){
     sum=0;
    for(int j=0;j<sz;j++){
    sum+=a[j];
    }
    if(i==0){
    current=max(sum,current);
    }else{
    current=max(current,max(sum,-sum));
    }
     for(int j=0;j<sz;j++){
      a[j]=a[j+1]-a[j];
      }
     sz--;
     }
   

    cout<<current<<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> a(n);
   for(int i=0;i<n;i++){
   cin>>a[i];
   }

   long long sum=0,current=-1e18;
   int sz=n;

   for(int i=0;i<n;i++){
     sum=0;
    for(int j=0;j<sz;j++){
    sum+=a[j];
    }
    if(i==0){
    current=max(sum,current);
    }else{
    current=max(current,max(sum,-sum));
    }
     for(int j=0;j<sz-1;j++){
      a[j]=a[j+1]-a[j];
      }
     sz--;
     }
   

    cout<<current<<endl;
    }

   }
Problem: 2062C - Cirno and Operations
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> a(n);
   for(int i=0;i<n;i++){
   cin>>a[i];
   }

   long long sum=0,current=-1e18;
   int sz=n;

   for(int i=0;i<n;i++){
     sum=0;
    for(int j=0;j<sz;j++){
    sum+=a[j];
    }
    if(i==0){
    current=max(sum,current);
    }else{
    current=max(current,max(sum,-sum));
    }
     for(int j=0;j<sz-1;j++){
      a[j]=a[j+1]-a[j];
      }
     sz--;
     }
   

    cout<<current<<endl;
    }

   }

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

   int main(){
   int t;cin>>t;

   while(t--){
   int n;cin>>n;

   vector<int> a(n);
   for(int i=0;i<n;i++){
   cin>>a[i];
   }

   long long sum=0,current=-1e18;
   int sz=n;

   for(int i=0;i<n;i++){
     sum=0;
    for(int j=0;j<sz;j++){
    sum+=a[j];
    }
    if(i==0){
    current=max(sum,current);
    }else{
    current=max(current,max(sum,-sum));
    }
     for(int j=0;j<sz-2;j++){
      a[j]=a[j+1]-a[j];
      }
     sz--;
     }
   

    cout<<current<<endl;
    }

   }
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 16):
#include <bits/stdc++.h>
using namespace std;

int diffCount(string a, string b)
{
    int count = 0;
    for (int i = 0; i < a.size(); i++)
    {
        if (a[i] != b[i])
            count++;
    }
    return count;
}

int dp_helper(string a, string b, string c, int i, int j, int k, vector<vector<int>> &arr)
{
    if(arr[i][j]!= -1){
        return arr[i][j];
    }
    if (i >= a.size() && j >= b.size())
    {
        return 0;
    }
    if (i >= a.size())
    {
        return arr[i][j] = diffCount(b.substr(j, b.size() - j), c.substr(k, c.size() - k));
    }
    else if (j >= b.size())
    {
        return arr[i][j] = diffCount(a.substr(i, a.size() - i), c.substr(k, c.size() - k));
    }
    if(a[i]==c[k] && b[j] == c[k]){
        return arr[i][j] =  min(dp_helper(a, b, c, i + 1, j, k + 1, arr), dp_helper(a, b, c, i, j + 1, k + 1, arr));
    }

    else if (a[i] == c[k])
    {
        return arr[i][j] = min(dp_helper(a, b, c, i + 1, j, k + 1, arr), 1 + dp_helper(a,b,c,i,j+1,k+1, arr));
    }
    else if (b[j] == c[k])
    {
        return arr[i][j] = min(dp_helper(a, b, c, i, j + 1, k + 1, arr), 1 + dp_helper(a, b, c, i + 1, j, k + 1, arr));
    }
    else
    {
        return arr[i][j] =  1 + min(dp_helper(a, b, c, i + 1, j, k + 1, arr), dp_helper(a, b, c, i, j + 1, k + 1, arr));
    }
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        
        string a, b, c;
        cin >> a >> b >> c;
        vector<vector<int>> arr(1000, vector<int> (1000, -1));
        cout << dp_helper(a, b, c, 0, 0, 0, arr)<<endl;
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include "bits/stdc++.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template<class K> using ordered_set =  tree<K, null_type, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T> using ordered_multiset = tree<pair<T, int>, null_type, less<pair<T, int>>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define uint unsigned int
#define pii pair <int , int>
#define pis pair <int, string>
#define mii map<int,int>
#define mmi map<int,map<int,int>>
#define mll map<long long, long long>
#define vi vector <int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second

#define forn(i, n) for (int i = 0; i < n; ++i)
#define foru(i, a, b) for (int i = a; i <= b; ++i)
#define ford(i, a, b) for (int i = a; i >= b; --i)
#define w(t) while(t--)

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 1e9 +1;
const ll MXX =  1e18 + 1;
using namespace std;

void solve(){
    int m,M;
    cin>>m>>M;
    int x=1;
    while(x<=M)x<<=1;
    x>>=1;
    int ans=M;
    while(x){
        ans^=x;
        if(ans<m)ans^=x;
        x>>=1;
    }
    if(ans==m){
        cout<<M<<' '<<ans<<' '<<ans+1<<endl;
    }
    else{
        cout<<M<<' '<<ans<<' '<<m<<endl;
    }


}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int T = 1;
    cin >> T;
    w(T) {
        solve();
    }

    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
//Problem Link :

#include<bits/stdc++.h>

#define ll long long int

#define endl '\n'

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main()

{

    fast;

    ll t;

    cin>>t;

    while(t--)

    {

        ll n,l,r,sum=0,suml=0,sumr=0;

        cin>>n>>l>>r;

        vector<ll>a,b,c;

        for(ll i=1;i<=n;i++)

        {

            ll x;cin>>x;

            if(i<l)a.push_back(x);

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

            {

                b.push_back(x);

                sum+=x;

            }

            else if(i>r)c.push_back(x);

        }

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

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

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



//        for(auto it:a)cout<<it<<" ";

//        cout<<endl;

//        for(auto it:b)cout<<it<<" ";

//        cout<<endl;

//        for(auto it:c)cout<<it<<" ";

//        cout<<endl;

        ll temp=sum;

        ll j=b.size()-1;

        for(ll i=0;i<a.size() && j>=0;)

        {

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

            {

                temp-=b[j];

                temp+=a[i];

                j--;

                i++;

            }

            else break;

        }

//        cout<<temp<<" "<<sum<<endl;



        sum=min(temp,sum);

        temp=sum;

        j=b.size()-1;

        for(ll i=0;i<c.size() && j>=0;)

        {

            if(c[i]<b[j])

            {

                temp-=b[j];

                temp+=c[i];

                j--;

                i++;

            }

            else break;

        }

        sum=min(temp,sum);

        cout<<sum<<endl;

    }

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
//Problem Link :

#include<bits/stdc++.h>

#define ll long long int

#define endl '\n'

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main()

{

    fast;

    ll t;

    cin>>t;

    while(t--)

    {

        ll n,l,r,sum=0,suml=0,sumr=0;

        cin>>n>>l>>r;

        vector<ll>a,b,c;

        for(ll i=1;i<=n;i++)

        {

            ll x;cin>>x;

            if(i<l)a.push_back(x);

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

            {

                b.push_back(x);

                sum+=x;

            }

            else if(i>r)c.push_back(x);

        }

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

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

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



//        for(auto it:a)cout<<it<<" ";

//        cout<<endl;

//        for(auto it:b)cout<<it<<" ";

//        cout<<endl;

//        for(auto it:c)cout<<it<<" ";

//        cout<<endl;

        ll temp=sum;

        ll j=b.size()-1;

        for(ll i=0;i<a.size() && j>=0;)

        {

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

            {

                temp-=b[j];

                temp+=a[i];

                j--;

                i++;

            }

            else break;

        }

//        cout<<temp<<" "<<sum<<endl;



        sum=min(temp,sum);

        temp=sum;

        j=b.size()-1;

        for(ll i=0;i<c.size() && j>=0;)

        {

            if(c[i]<b[j])

            {

                temp-=b[j];

                temp+=c[i];

                j--;

                i++;

            }

            else break;

        }

        sum=min(temp,sum);

        cout<<sum<<endl;

    }

    return 0;

}





Submission (verdict: Runtime error on test 2):
//Problem Link :

#include<bits/stdc++.h>

#define ll long long int

#define endl '\n'

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main()

{

    fast;

    ll t;

    cin>>t;

    while(t--)

    {

        ll n,l,r,x;

        cin>>n>>l>>r;

        vector<ll>b,c;

        for(ll i=1;i<=n;i++)

        {

            cin>>x;

            if(x>=l && x<=n)b.push_back(x);

            if(x<=r && x>=1)c.push_back(x);

        }

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

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



        ll sum1=0,sum2=0;

        for(ll i=0;i<(r-l+1);i++)

        {

            sum1+=b[i];

            sum2+=c[i];

        }

        cout<<min(sum1,sum2)<<endl;

    }

    return 0;

}