ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

#define FAST_IO             (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define ll long long int
#define int long long 
#define endl "\n"
#define MAX INT_MAX
#define MIN INT_MIN
#define pb push_back

using namespace std;

void solve()
{
    int n, l, r;
    cin >> n >> l >> r;

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

    int k = r-l+1;
    int ans = 0;
    vector<int> :: iterator it;
    for (int i=0; i<k; i++) {
        it = min_element(a.begin(), a.end());
        ans += *it;
        a.erase(it);
    }

    cout << ans << endl;
}

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

    while (t--)
        solve();

    return 0;
}


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

#include <string>



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

#define ll long long int

#define int long long 

#define endl "\n"

#define MAX INT_MAX

#define MIN INT_MIN

#define pb push_back



using namespace std;



void solve()

{

    int n, l, r;

    cin >> n >> l >> r;

    

    vector<int> a(n);

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

        cin >> a[i];

    }



    int k = r-l+1;



    int originalSum = accumulate(a.begin()+(l-1), a.begin()+r, 0);



    vector<int> sa = a;

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



    int minPossibleSum = accumulate(sa.begin(), sa.begin()+k, 0);



    cout << min(originalSum, minPossibleSum) << endl;

}



int32_t main()

{

    FAST_IO;

    int t;

    cin >> t;



    while (t--)

        solve();



    return 0;

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


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



int checku2(int a,int n){
  int e=(3*a*a);
  int countu=0;
  if(e<=n) countu++;
  e=(a+1)*(a)+(a+1)*(a)+(a*a);
  if(e<=n) countu++;
  e=(a+1)*(a+1)+(a+1)*(a)+(a+1)*(a);
  if(e<=n) countu++;
  e=(a+2)*(a)+(a+2)*(a)+(a*a);
  if(e<=n){
  countu++;
  }
  return countu;
}
int checku1(int a,int n){
  int e=(3*a*a);
  int countu=0;
  if(e<=n) countu++;
   e=(((a+1)*(a))+((a+1)*(a))+(a*a));
   if(e<=n) countu++;
   return countu;
}
int checku(vector<vector<int>> &vecu,int a[],int b){
  if(a[b]==0){
    vecu[b][0]=0;
    return 1;
  }
  else if(a[b]==2){
    int x=checku(vecu,a,vecu[b][1])+checku(vecu,a,vecu[b][2]);
    vecu[b][0]=x;
    return 1+x;
  }
  else{
    int x=checku(vecu,a,vecu[b][1]);
    vecu[b][0]=x;
    return 1+x;
  }
  return 0;
}
void sol()
{
   int n;
  //  cin>>n;
  //  int a[n];
  //  vector<string> vecu(n);
  //  int z=0;
  //  int x=0;
  // for(int i=0;i<n;i++){
  //   cin>>a[i];
  //   z=z+a[i];
  // }
  string t;
  cin>>t;
  n=t.length();
  vector<int> vecu(n,-1);
  string l="";
  int y=0;
  while(l.size()!=n){
   if(vecu[y]==1){
      y++;
      continue;
   }
   else{
    int x=(int)(t[y]-48);
    int r=y+1;
    int z=y;
    int f=1;
    while(r<n && r<(y+9)){
      if(vecu[r]==-1){
      int b=(int)(t[r]-48)-f;
      if(b>x){
        x=b;
        z=r;
      }
      f++;
      }
      r++;
    }
    l=l+(char)(x+48);
    vecu[z]=1;
   }
  }
  cout<<l;
  //  for(int i=0;i<n;i++){
    
  //  }


//    int l=n;
//   //  if(t[0]=='s'){
//   for(int i=0;i<n;i++){
//    if(t[i]=='p'){
//     l=i;
//     break;
//    }
//    x++;
//   }
//   //  }
//   // if(t[n-1]=='p'){
//   for(int i=n-1;i>=l;i--){
//    if(t[i]=='s'){
//     break;
//    }
//    y++;
//   }
//   // }
//   // cout<<x<<" "<<y<<" "<<l;
//   if(z==n){
//     cout<<"Yes";
//   }
//   else if(x+y==n){
//     if((x>0 && t[0]=='s') || y==0){
//       cout<<"Yes";
//     }
//     else if((y>0 && t[n-1]=='p') || x==0){
//       cout<<"Yes";
//     }
//     else{
// cout<<"NO";
//     }
//   }
//   else{
//     cout<<"NO";
//   }
  //  for(int i=0;i<n;i++){
  //   cout<<b[i]<<" ";
  //  }
   //  for(int i=0;i<n;i++){
  //   for(int j=0;j<l;j++){
  //     cout<<a[j][i]<<" ";
  //   }
  //   cout<<endl;
  //  }
  //  cout<<endl;
//  cout<<ansu;
     //  for(int i=0;i<n;i++){
  //   cout<<z[i];
  //  }
  // int x,y;
  // cin>>x>>y;
  //  cout<<ans;
    //  cout<<c1;
  //  cout<<ans<<endl;
  cout<<endl;
// cout<<f<<endl;
 return ;
 }
int32_t main(){
    int t;
    cin>>t;
    while(t--){
        sol();
    }
    // sol();

}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

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

void solve() { 
    int n, m; cin >> n >> m;
    map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        cnt[x]++;
    }
    priority_queue<pair<int, int>> pq;
    for (int i = 0; i < m; i++) {
        int x; cin >> x;
        pq.push({x, 1});
    }
    while (!pq.empty()) {
        int c = pq.top().first;
        int am = pq.top().second;
        pq.pop();
        if (n == 0) {
            cout << "No\n";
            return ;
        }
        if (cnt[c]) {
            if (am <= cnt[c]) {
                cnt[c] -= am;
                n-=am;
                continue;
            }
            else {
                am -= cnt[c];
                n -= cnt[c];
                cnt[c] = 0;
            }
        }
        if (c == 1) {
            cout << "No\n";
            return;
        }
        if (c % 2 == 0) pq.push({c / 2, 2*am});
        else {
            pq.push({c / 2 + 1, am});
            pq.push({c / 2, am});
        }
    }
    if (n == 0) {
        cout << "Yes\n";
    }
    else cout << "No\n";
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t; cin >> t;
    while (t--) solve();
    return 0;
}

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

void solve() { 
    int n, m; cin >> n >> m;
    map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        cnt[x]++;
    }
    priority_queue<pair<int, int>> pq;
    for (int i = 0; i < m; i++) {
        int x; cin >> x;
        pq.push({x, 1});
    }
    while (!pq.empty()) {
        int c = pq.top().first;
        int am = pq.top().second;
        pq.pop();
        while (!pq.empty() && pq.top().first == c) {
            am += pq.top().second;
            pq.pop();
        }
        if (n == 0) {
            cout << "No\n";
            return ;
        }
        if (cnt[c]) {
            if (am <= cnt[c]) {
                cnt[c] -= am;
                n-=am;
                continue;
            }
            else {
                am -= cnt[c];
                n -= cnt[c];
                cnt[c] = 0;
            }
        }
        if (c == 1) {
            cout << "No\n";
            return;
        }
        if (c % 2 == 0) pq.push({c / 2, 2*am});
        else {
            pq.push({c / 2 + 1, am});
            pq.push({c / 2, am});
        }
    }
    if (n == 0) {
        cout << "Yes\n";
    }
    else cout << "No\n";
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t; cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


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

void solve() { 
    int n, m; cin >> n >> m;
    map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        cnt[x]++;
    }
    priority_queue<pair<int, int>> pq;
    for (int i = 0; i < m; i++) {
        int x; cin >> x;
        pq.push({x, 1});
    }
    while (!pq.empty()) {
        int c = pq.top().first;
        int am = pq.top().second;
        pq.pop();
        if (n == 0) {
            cout << "No\n";
            return ;
        }
        if (cnt[c]) {
            if (am <= cnt[c]) {
                cnt[c] -= am;
                n-=am;
                continue;
            }
            else {
                am -= cnt[c];
                cnt[c] = 0;
            }
        }
        if (c == 1) {
            cout << "No\n";
            return;
        }
        if (c % 2 == 0) pq.push({c / 2, 2*am});
        else {
            pq.push({c / 2 + 1, am});
            pq.push({c / 2, am});
        }
    }
    if (n == 0) {
        cout << "Yes\n";
    }
    else cout << "No\n";
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t; cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

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

void solve() { 
    int n, m; cin >> n >> m;
    map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        cnt[x]++;
    }
    priority_queue<pair<int, int>> pq;
    for (int i = 0; i < m; i++) {
        int x; cin >> x;
        pq.push({x, 1});
    }
    while (!pq.empty()) {
        int c = pq.top().first;
        int am = pq.top().second;
        pq.pop();
        if (n == 0) {
            cout << "No\n";
            return ;
        }
        if (cnt[c]) {
            if (am <= cnt[c]) {
                cnt[c] -= am;
                n-=am;
                continue;
            }
            else {
                am -= cnt[c];
                cnt[c] = 0;
            }
        }
        if (c == 1) {
            cout << "No\n";
            return;
        }
        if (c % 2 == 0) pq.push({c / 2, 2*am});
        else {
            pq.push({c / 2 + 1, am});
            pq.push({c / 2, am});
        }
    }
    if (n == 0) {
        cout << "Yes\n";
    }
    else cout << "No\n";
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t; cin >> t;
    while (t--) solve();
    return 0;
}

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

void solve() { 
    int n, m; cin >> n >> m;
    map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        cnt[x]++;
    }
    priority_queue<pair<int, int>> pq;
    for (int i = 0; i < m; i++) {
        int x; cin >> x;
        pq.push({x, 1});
    }
    while (!pq.empty()) {
        int c = pq.top().first;
        int am = pq.top().second;
        pq.pop();
        if (n == 0) {
            cout << "No\n";
            return ;
        }
        if (cnt[c]) {
            if (am <= cnt[c]) {
                cnt[c] -= am;
                n-=am;
                continue;
            }
            else {
                am -= cnt[c];
                n -= cnt[c];
                cnt[c] = 0;
            }
        }
        if (c == 1) {
            cout << "No\n";
            return;
        }
        if (c % 2 == 0) pq.push({c / 2, 2*am});
        else {
            pq.push({c / 2 + 1, am});
            pq.push({c / 2, am});
        }
    }
    if (n == 0) {
        cout << "Yes\n";
    }
    else cout << "No\n";
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t; cin >> t;
    while (t--) solve();
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

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

void solv() {
    ll l, r;
    cin >> l >> r;

  
    ll msb_diff = 0;
    for (ll bit = 31; bit >= 0; --bit) {
        if ((l & (1LL << bit)) != (r & (1LL << bit))) {
            msb_diff = bit;
            break;
        }
    }

    
    ll mid = (1LL << (msb_diff + 1)) - 1; 
    if (mid > r) mid = r; 

    cout << l << " " << mid << " " << r << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--) {
        solv();
    }

    return 0;
}


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

void solv() {
    ll l, r;
    cin >> l >> r;

  
    ll msb_diff = 0;
    for (ll bit = 31; bit >= 0; --bit) {
        if ((l & (1LL << bit)) != (r & (1LL << bit))) {
            msb_diff = bit;
            break;
        }
    }

    
    ll a= l|(1LL <<(msb_diff)) - 1; 
    ll b=a+1;
    ll c=a==l? r:l;
   

    cout << a<< " " << b << " " << c<< endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--) {
        solv();
    }

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 1):
    #include <bits/stdc++.h>
    #define ll long long 
    using namespace std;
   
     
    void solv() {
      ll l,r;
      cin>>l>>r;
      ll mid=l;
      ll left=0,right=0;
      for(int i=l;i<=r;i++){
        if((i^l)+(i^r)>=left+right) {
            left=i^l;
            right=i^r;
            mid=i;
        }    
      }
      cout<<l<<" "<<mid<<" "<<r<<endl;
     }

     
     
     
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
      int t;
       cin>>t;
       while(t--){
       solv();
      }
     
    }


Submission (verdict: Wrong answer on test 1):
    #include <bits/stdc++.h>
    #define ll long long 
    using namespace std;
   
     
    void solv() {
      ll l,r;
      cin>>l>>r;
      ll mid=(l+r)/2;
      cout<<l<<" "<<mid<<" "<<r<<endl;
     }

     
     
     
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
      int t;
       cin>>t;
       while(t--){
       solv();
      }
     
    }
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
    #include <bits/stdc++.h>
    #define ll long long 
    using namespace std;
   
     
    void solv() {
      ll l,r;
      cin>>l>>r;
      ll mid=(l+r)/2;
      cout<<l<<" "<<mid<<" "<<r<<endl;
     }

     
     
     
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
      int t;
       cin>>t;
       while(t--){
       solv();
      }
     
    }


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

void solv() {
    ll l, r;
    cin >> l >> r;

  
    ll msb_diff = 0;
    for (ll bit = 31; bit >= 0; --bit) {
        if ((l & (1LL << bit)) != (r & (1LL << bit))) {
            msb_diff = bit;
            break;
        }
    }

    
    ll mid = (1LL << (msb_diff + 1)) - 1; 
    if (mid > r) mid = r; 

    cout << l << " " << mid << " " << r << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--) {
        solv();
    }

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 1):
    #include <bits/stdc++.h>
    #define ll long long 
    using namespace std;
   
     
    void solv() {
      ll l,r;
      cin>>l>>r;
      ll mid=l;
      ll left=0,right=0;
      for(int i=l;i<=r;i++){
        if((i^l)+(i^r)>=left+right) {
            left=i^l;
            right=i^r;
            mid=i;
        }    
      }
      cout<<l<<" "<<mid<<" "<<r<<endl;
     }

     
     
     
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
      int t;
       cin>>t;
       while(t--){
       solv();
      }
     
    }
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 Fastio ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long double lld;

typedef unsigned long long ull;

typedef long long ll;



constexpr int MOD=1e9+7;



#ifdef ARPIT

#include "karpit.h"

#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)

#else

#define deb(x...)

#endif





signed main() {

Fastio

#ifdef ARPIT

freopen("error.txt", "w", stderr);

#endif

int t  = 1;

cin>>t;

// Solve Here

while(t--){

string s;

cin>>s;

int n=s.size();

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

int f=1;

for(int j=i;j>0;j--){

if(s[j]-'0'-f>s[j-1]-'0'){

s[j]=(s[j]-f);

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

}

}

}

cout<<s<<"\n";



}

return 0;

}

Submission (verdict: Accepted):
/* ??????????????? ????????? ?????? ??? ??? ??????????|

?? ?????? ??????????????????? ????????????????????||  */



#include<bits/stdc++.h>

#define Fastio ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long double lld;

typedef unsigned long long ull;

typedef long long ll;



constexpr int MOD=1e9+7;



#ifdef ARPIT

#include "karpit.h"

#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)

#else

#define deb(x...)

#endif





signed main() {

Fastio

#ifdef ARPIT

freopen("error.txt", "w", stderr);

#endif

int t  = 1;

cin>>t;

// Solve Here

while(t--){

string s;

cin>>s;

int n=s.size();

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

int f=1;

for(int j=i;j>0;j--){

if(s[j]-'0'-f>s[j-1]-'0'){

s[j]=(s[j]-f);

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

}else break;

}

}

cout<<s<<"\n";



}

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 Fastio ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long double lld;

typedef unsigned long long ull;

typedef long long ll;



constexpr int MOD=1e9+7;



#ifdef ARPIT

#include "karpit.h"

#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)

#else

#define deb(x...)

#endif





signed main() {

Fastio

#ifdef ARPIT

freopen("error.txt", "w", stderr);

#endif

int t  = 1;

cin>>t;

// Solve Here

while(t--){

string s;

cin>>s;

int n=s.size();

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

int maxi=s[0]-'0',f=0;

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

if(s[j]-'0'-j>maxi){

maxi=s[j]-'0'-j;

f=j;

}

}

cout<<maxi;

s.erase(f,1);

}cout<<"\n";



}

return 0;

}

Submission (verdict: Time limit exceeded on test 6):
/* ??????????????? ????????? ?????? ??? ??? ??????????|

?? ?????? ??????????????????? ????????????????????||  */



#include<bits/stdc++.h>

#define Fastio ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long double lld;

typedef unsigned long long ull;

typedef long long ll;



constexpr int MOD=1e9+7;



#ifdef ARPIT

#include "karpit.h"

#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)

#else

#define deb(x...)

#endif





signed main() {

Fastio

#ifdef ARPIT

freopen("error.txt", "w", stderr);

#endif

int t  = 1;

cin>>t;

// Solve Here

while(t--){

string s;

cin>>s;

int n=s.size();

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

int f=1;

for(int j=i;j>0;j--){

if(s[j]-'0'-f>s[j-1]-'0'){

s[j]=(s[j]-f);

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

}

}

}

cout<<s<<"\n";



}

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 Fastio ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long double lld;

typedef unsigned long long ull;

typedef long long ll;



constexpr int MOD=1e9+7;



#ifdef ARPIT

#include "karpit.h"

#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)

#else

#define deb(x...)

#endif





signed main() {

Fastio

#ifdef ARPIT

freopen("error.txt", "w", stderr);

#endif

int t  = 1;

cin>>t;

// Solve Here

while(t--){

string s;

cin>>s;

int n=s.size();

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

int maxi=s[0]-'0',f=0;

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

if(s[j]-'0'-j>maxi){

maxi=s[j]-'0'-j;

f=j;

}

}

cout<<maxi;

s.erase(f,1);

}cout<<"\n";



}

return 0;

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

Previous submission (verdict: Compilation error):
/* परिवर्तिनि संसारे मृतः को वा न जायते |

   स  जातो येन जातेन याति वंश समुन्नतिम्||  */

   

#include<bits/stdc++.h>

#define Fastio ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long double lld;

typedef unsigned long long ull;

typedef long long ll;



constexpr int MOD=1e9+7;



#ifdef ARPIT

#include "karpit.h"

#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)

#else

#define deb(x...)

#endif





signed main() {

Fastio

#ifdef ARPIT

    freopen("error.txt", "w", stderr);

#endif

    int t  = 1;

    cin>>t; 

    // Solve Here 

    while(t--){

      ll n,l,r;

      cin>>n>>l>>r;

      vector<ll> a(n),left,right,mid;

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

        cin>>a[i];

        if(i<l-1)left.push_back(a[i]);

        else if(i>=l-1&&i<=r-1)mid.push_back(a[i]);

        else right.push_back(a[i]);

      }

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

      sort(mid.rbegin(),r.rend());

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



      int i=0;

      ll sum1=0;

      while(i<mid.size()){

        if(i<left.size()) sum1+=min(mid[i],left[i]);

        else sum1+=mid[i];

        i++;

      }

      i=0;

      ll sum2=0;

      while(i<mid.size()){

        if(i<right.size()) sum2+=min(mid[i],right[i]);

        else sum2+=mid[i];

        i++;

      }



      cout<<min(sum1,sum2)<<"\n";

    }

    return 0;

}

Submission (verdict: Accepted):
/* परिवर्तिनि संसारे मृतः को वा न जायते |
   स  जातो येन जातेन याति वंश समुन्नतिम्||  */
   
#include<bits/stdc++.h>
#define Fastio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long double lld;
typedef unsigned long long ull;
typedef long long ll;

constexpr int MOD=1e9+7;

#ifdef ARPIT
#include "karpit.h"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif


signed main() {
Fastio
#ifdef ARPIT
    freopen("error.txt", "w", stderr);
#endif
    int t  = 1;
    cin>>t; 
    // Solve Here 
    while(t--){
      ll n,l,r;
      cin>>n>>l>>r;
      vector<ll> a(n),left,right,mid;
      for(int i=0;i<n;i++){
        cin>>a[i];
        if(i<l-1)left.push_back(a[i]);
        else if(i>=l-1&&i<=r-1)mid.push_back(a[i]);
        else right.push_back(a[i]);
      }
      sort(left.begin(),left.end());
      sort(mid.rbegin(),mid.rend());
      sort(right.begin(),right.end());

      int i=0;
      ll sum1=0;
      while(i<mid.size()){
        if(i<left.size()) sum1+=min(mid[i],left[i]);
        else sum1+=mid[i];
        i++;
      }
      i=0;
      ll sum2=0;
      while(i<mid.size()){
        if(i<right.size()) sum2+=min(mid[i],right[i]);
        else sum2+=mid[i];
        i++;
      }

      cout<<min(sum1,sum2)<<"\n";
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
/* परिवर्तिनि संसारे मृतः को वा न जायते |

   स  जातो येन जातेन याति वंश समुन्नतिम्||  */

   

#include<bits/stdc++.h>

#define Fastio ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

typedef long double lld;

typedef unsigned long long ull;

typedef long long ll;



constexpr int MOD=1e9+7;



#ifdef ARPIT

#include "karpit.h"

#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)

#else

#define deb(x...)

#endif





signed main() {

Fastio

#ifdef ARPIT

    freopen("error.txt", "w", stderr);

#endif

    int t  = 1;

    cin>>t; 

    // Solve Here 

    while(t--){

      ll n,l,r;

      cin>>n>>l>>r;

      vector<ll> a(n);

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

        cin>>a[i];

      }

      if(l-2>=0) sort(a.begin(),a.begin()+l-2);

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

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



      deb(a);

      

      int i=r-1,j=r;

      ll sum1=0,sum2=0;

      while(i>=l-1){

        if(j<n)sum1+=min(a[i],a[j]);

        else{

          sum1+=a[i];

        }

        i--;

        j++;

      }

      i=r-1,j=0;

      while(i>=l-1){

        if(j<l-1) sum2+=min(a[i],a[j]);

        else sum2+=a[i];

      

        i--;j++;

      }



      cout<<min(sum1,sum2)<<"\n";

    }

    return 0;

}