ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 265 ms):
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

multiset<int> st;

bool dfs(int x) {
  auto it = st.find(x);
  if (it == st.end()) {
    if (x == 1) return false;
    int l = x >> 1;
    int r = x - l;
    return dfs(l) && dfs(r);
  }
  st.erase(it);
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    st.clear();
    for (int i = 0, x; i < n; i++) {
      cin >> x;
      st.insert(x);
    }
    bool ans = true;
    vector<int> a(m);
    for (int i = 0; i < m; i++) cin >> a[i];
    sort(a.begin(), a.end());
    for (int i = 0, x; i < m; i++) {
      if (!dfs(a[m - i - 1])) {
        ans = false;
        break;
      }
    }
    cout << ((ans && st.empty())? "Yes" : "No") << endl;
  }
  return 0;
}

Solution 2 (runtime: 374 ms):
#include<bits/stdc++.h>
using namespace std;
#define vl(a) vector<ll> a
#define vp(a,b) a.push_back(b)
#define vi(a) vector<int> a

#define c(a) cout<<a<<"\n"
#define yo cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define kak cout

#define f(a) for(int i=0;i<a;i++)
#define see(v) for(auto i:v){\
cout<<i<<" ";\
}cout<<endl

typedef long long ll;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
      int t;
      cin>>t;
      while(t--){
      int n,m;
      cin>>n>>m;
      queue<int> q;multiset<int> mp;
      f(n){
        int l;cin>>l;
        mp.insert(l);
       }
       f(m){
        int l;cin>>l;
        q.push(l);
       }

       while((mp.size()>=q.size())&&(!q.empty())){
        int p=q.front();
        q.pop();
        if(mp.count(p)){
            mp.erase(mp.find(p));
        }else{
            if(p%2){
            q.push(p/2),q.push(p/2+1);}
            else{
                q.push(p/2);q.push(p/2);
            }
        }
       }
       if(mp.size()<q.size())c("No");
       else{
       if(mp.size()==0)c("Yes");else c("No");
       }
      }
return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
#include <vector>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#define endl "\n"

template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }

#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define out( x ) #x << " = " << x << "  "

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template<typename T, typename B = decay<decltype(*begin(declval<T>()))>, typename enable_if<!is_same<T, string>::value>::type* = nullptr>
ostream& operator <<(ostream &os, const T &c) {
	bool f = false;
	os << "(";
	for(const auto &x : c) {
		if(f) {
			os << ", ";
		}
		f = true;
		os << x;
	}return os << ")";
}

typedef long long ll;
const ll mod = 1e9 + 7;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

const int MAX_N = 1e6 + 10;

void solve() {

	std::string s;
	cin >> s;

	int n = (int)s.size();
    for (int i = 0; i < n ; i++) {
        int mx = s[i] - '0', intMx = i;
        for (int j = i; j < std::min(i + 10, n ); j++) {
            if (s[j] - '0' - (j - i) > mx) {
                mx = s[j] - '0' - (j - i);
                intMx = j;
            }
        }
        while (intMx > i) {
            swap(s[intMx], s[intMx - 1]);
            intMx--;
        }

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

	cerr << out( s ) << endl;

	for( auto j : s ) std::cout << j ;
	std::cout << endl;

}

signed main() {
#ifndef LOCAL
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#endif

	int t = 1;
	cin >> t;
	while(t --) {
		solve();
	}

	return 0;
}


Solution 2 (runtime: 109 ms):
#include <bits/stdc++.h>

using namespace std;
int stoi(char s)
{
    if(s=='1')
        return 1;
    else if(s=='2')
        return 2;
    else if(s=='3')
        return 3;
    else if(s=='4')
        return 4;
    else if(s=='5')
        return 5;
    else if(s=='6')
        return 6;
    else if(s=='7')
        return 7;
    else if(s=='8')
        return 8;
    else if(s=='9')
        return 9;
    else return 0;

}
int main()
{
    int t,ma,b;
    cin>>t;
    while(t--)
    {   string s;
        cin>>s;
        int n=s.length();
        for(int i=0;i<n;i++)
        {ma=stoi(s[i]);
         b=i;


            for(int j=i;j<n&&j<i+9;j++)
          {  if(stoi(s[j])-(j-i)>ma){
              ma=max(stoi(s[j])-(j-i),ma);
              b=j;

              }
          }

          int x=stoi(s[b])-(b-i);
          string z;
          for(int v=b-1;v>=i;v--){
            swap(s[b],s[v]);
            b=v;
            }
        z=to_string(x);
        s[b]=z[0];

        }cout<<s<<endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 250 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() 
{
    int t;
    cin>>t;
    while(t--){
      int n, k;
      cin>>n>>k;
      vector<ll> vec;
      for(int i=0; i<n; i++){
        ll x;
        cin>>x;
        vec.push_back(x);
      }
      map<int, int> mp;
      for(int i=0; i<vec.size(); i++){
        mp[vec[i]]++;
      }
      vector<vector<int>> kv;
      for(auto i:mp){
        vector<int> ins(2);
        ins[0] = i.second;
        ins[1] = i.first;
        kv.push_back(ins);
      }
      sort(kv.begin(), kv.end());
      int i=0;
      while(k>0 && i<kv.size()){
        if(k>=kv[i][0]){
          k-=kv[i][0];
          i++;
        }
        else{
          break;
        }
      }
      if(i == kv.size()) cout<<1<<endl;
      else{
      cout<<kv.size()-i<<endl;
      }
    }
    return 0;
}

Solution 2 (runtime: 124 ms):
#include <bits/stdc++.h>
using namespace std;

void q2057C()
{
    int l, r;
    cin >> l >> r;
    int k = 31 - __builtin_clz(l ^ r); //count first digit that defer
    int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l);
    std::cout << a << " " << b << " " << c << "\n";
}

void q2057B()
{
    int n,k;
    cin >> n >> k;
    map<int,int> mp;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        mp[temp]++;
    }
    priority_queue<int, vector<int>, greater<int>> pq;
    for (auto [a,b] : mp) {
        pq.push(b);
    }
    while (pq.size() > 1 && k > 0) {
        k -= pq.top();
        if (k >= 0) pq.pop();
    }
    cout << pq.size() << "\n";
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;
    std::cin >> t;

    while (t--) {
        q2057B();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200006;
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define ll long long
const long long mod = 1e9 + 7;
unsigned ll w, h, n;
// ll gcd(ll n, ll k)
// {
//    if (n == 0)
//    {
//       return k;
//    }
//    return gcd(k % n, n);
// }

void solve()
{
   int n, l, r;
   cin >> n >> l >> r;
   vector<int> a, b, c;
   int p[n];
   for (int i = 0; i < n; i++)
   {
      cin >> p[i];
   }
   ll sum = 0;
   for (int i = 0; i < n; i++)
   {
      if (i < l - 1)
      {
         a.push_back(p[i]);
      }
      else if (i > r - 1)
      {
         b.push_back(p[i]);
      }
      else
      {
         sum += p[i];
         c.push_back(p[i]);
      }
   }
   if (a.size())
   {
      sort(a.begin(), a.end());
   }
   if (b.size())
   {
      sort(b.begin(), b.end());
   }
   if (c.size())
   {
      sort(c.rbegin(), c.rend());
   }
   ll ans = sum;
   ll ans2 = sum;
   ll cur_sum = 0;
   // for (int i = 0; i < c.size(); i++)
   // {
   //    cout << c[i] << " ";
   // }
   // cout << endl;
   // cout << ans << endl;
   for (int i = 0; i < a.size() && i < c.size(); i++)
   {
      cur_sum += a[i];
      cur_sum -= c[i];
      ans = min(ans, ans2 + cur_sum);
   }
   // cout << ans << endl;
   cur_sum = 0;
   for (int i = 0; i < b.size() && i < c.size(); i++)
   {
      cur_sum += b[i];
      cur_sum -= c[i];
      // cout << cur_sum << endl;
      ans = min(ans, ans2 + cur_sum);
      // cout << ans << endl;
   }
   cout << ans << endl;
}

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

   return 0;
}


Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N=2e5+10;
int a[N];

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
    
    int t;
    cin>>t;
    while(t--){
    	ll sum=0;
    	int n,l,r;
    	cin>>n>>l>>r;
    	priority_queue<ll, vector<ll>, greater<ll>> b,d;
    	priority_queue<ll> c,m;
    	for(int i=1;i<=n;i++){
    		cin>>a[i];
    		if(i<l) b.push(a[i]);
			else if(i>r) d.push(a[i]);
			else c.push(a[i]);
			
			if(i>=l&&i<=r) sum+=a[i]; 
		} 
		
    	m=c;
    	ll res1=sum,res2=sum;
    	if(b.size()>0){
    		while(b.top()<c.top()){
    			ll x=b.top(),y=c.top();
	    		res1+=x,res1-=y;
	    		b.push(y),c.push(x);
	    		b.pop(),c.pop();
			}
		}
    	
		if(d.size()>0){
			while(d.top()<m.top()){
				ll x=d.top(),y=m.top();
	    		res2+=x,res2-=y;
	    		d.push(y),m.push(x);
	    		d.pop(),m.pop();
			}
		}
		
		
		
		if(res1>res2) cout<<res2<<endl;
		else cout<<res1<<endl;
    }
	
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>

using namespace std;

void inline solve() {
    int l, r;
    cin >> l >> r;
    int a = 0, b = 0, c = 0;
    for (int mask = 1 << 30; mask > 0; mask >>= 1) {
        // cout << "A " << a << ' ' << b << ' ' << c << ' ' << mask << '\n';
        if ((l & mask) == (r & mask)) {
            a |= (l & mask);
            b |= (l & mask);
            c |= (l & mask);
        } else {
            a |= mask;
            b |= mask-1;
            if (b - 1 >= l) c = b-1;
            else c = a + 1;
            break;
        }
    }
    cout << a << ' ' << b << ' ' << c << '\n';
    // cout << (a ^ b) + (a ^ c) + (b ^ c) << '\n';
}

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

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

    return 0;
}

Solution 2 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
int main()
{
 ios::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin>>t;
while(t--){
 long long l,r;
 cin>>l>>r;
 vector<int>a;
 vector<int>b;
 int n1=1,n2=1;
 int i=l;
 while(i>1){
  a.push_back(i%2);
  i=i/2;
  n1++;
 }
 a.push_back(i%2);
  i=r;
 while(i>1){
  b.push_back(i%2);
  i=i/2;
  n2++;
 }
 b.push_back(i%2);
 if(r-l==2)  cout<<l<<" "<<l+1<<" "<<r<<endl;
 else if(n1!=n2) {
  n2--;
    int a=pow(2,n2);
    int b=0;
    n2--;
    while(n2>=0){
       b+=pow(2,n2);
       n2--;
    }
    if(a!=l) cout<<l<<" "<<a<<" "<<b<<endl;
    else cout<<a<<" "<<b<<" "<<b+1<<endl;

 }
 else {
  int cnt=0;
  for(int i=n1-1;i>=0;i--){
    if(a[i]==b[i]) cnt++;
    else break;
  }
  int bit= n1-cnt-1;
  //cout<<bit<<endl;
  //cout<<cnt<<endl;
  int a=0;
  for(int i=1;i<=cnt;i++){
    a+=pow(2,n2-i);
  }
     int b=a;
   a+=pow(2,bit);

   if(a>r) {
     a=pow(2,n1-1)+pow(2,bit);
     b=pow(2,n1-1);
     //cout<<"puk"<<endl;
   }
   //cout<<b<<endl;
   for(int i=bit-1;i>=0;i--) b+=pow(2,i);
  // cout<<b<<endl;
   cout<<l<<" "<<b<<" "<<a<<endl;
 }
 
}
 return 0;
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 671 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back

bool checkOverlap(int node1, int node2, set<pair<int, int>> &st){
  if(st.find({node1, node2}) != st.end() || st.find({node2, node1}) != st.end()){
    return false;
  }

  return true;
}

void getCardinality(unordered_map<int, int> &mp, vector<pair<int,int>> &cardinality){
   for(auto it: mp){
    cardinality.pb({it.second, it.first});
   }
}

int findComponents(set<pair<int, int>> &st, vector<pair<int,int>> &c, int n){
  if(n <= 2) return 0;
  if(c[0].first == c[1].first && c[1].first == c[2].first){
    return (2 * c[0].first) - 1;
  }
  else if(c[0].first == c[1].first){
    if(checkOverlap(c[0].second, c[1].second, st)){
      return (2 * c[0].first) - 1;
    }
    else{
      return (2 * c[0].first) - 2;
    }
  }
  else{
    if(checkOverlap(c[0].second, c[1].second, st)){
      return (c[0].first + c[1].first) - 1;
    }
    else{
      int temp = (c[0].first + c[1].first) - 2;
      for(int i = 2; i<n; i++){
        if(c[i - 1].first == c[i].first){
          if(checkOverlap(c[0].second, c[i].second, st)){
            temp = (c[0].first + c[i].first) - 1;
            break;
          }
        }
        else{
          break;
        }
      }
      return temp;
    }
  }
  return -1;
}

int main()
{
  int t;
  cin>>t;
  while(t){
    int n;
    cin>>n;
    int u, v;
    set<pair<int, int>> st;
    unordered_map<int, int> mp;
    for(int i = 1; i<n; i++){
     cin>>u>>v;
     st.insert({u, v});
     mp[u]++;
     mp[v]++;
   }
    
   vector<pair<int, int>> cardinality;
   getCardinality(mp, cardinality);
   sort(cardinality.begin(), cardinality.end(), greater<pair<int, int>>());
   cout<<findComponents(st, cardinality, n)<<"\n";
   t--;
 }
 return 0;
}

Solution 2 (runtime: 233 ms):
#include<bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define ll long long

using namespace std;

int main (){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;cin>>t;
    while(t--){
    	int n;cin>>n;
    	vector<vector<int>> tree(n);
    	vector<int> num(n,0);
    	
    	for(int i = 0; i < (n-1); ++i){
    		int u,v;cin>>u>>v;
			u--,v--;
			num[u]++;
			num[v]++;
			tree[u].pb(v);
			tree[v].pb(u);

		}
		//after first step I have sol = edges of max num
		int pos_max = 0;
		for(int i = 0; i < n; ++i){
			if(num[i] > num[pos_max]){
				pos_max = i;
			} 
		}
		int best_count = 10000000; 
		for(int i = 0; i < n; ++i){
			if(num[i] == num[pos_max]){
				int count = 0; 
				for(auto j : tree[i]){
					if(num[j] == num[pos_max]) count++;	
				}
				if(count  < best_count){
					pos_max = i; 
					best_count = count;
				}
			}
		}
		int sol = num[pos_max];
		num[pos_max ] = 0;
		
		for(auto i : tree[pos_max])	num[i]--;
		/*
		for(auto i : num) cout<<i<<" ";
		cout<<"\n";
		*/
		for(int i = 0; i < n; ++i){
			if(num[i] > num[pos_max]) pos_max = i;
		}
		sol  = sol - 1 + num[pos_max]; 
		cout<<sol<<"\n";
	}

}
/*

5
1 2
1 3
2 4
3 5
*/
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 342 ms):
#include<bits/stdc++.h>
using namespace std;
int main(){
       int t;
       cin>>t;
       while(t--){
             int n;
             cin>>n;
             vector<int>num(n);
             for(int i=0;i<n;i++){
                 cin>>num[i];
             }
             int flag=0;
             for(int i=0;i<n-1;i++){
                 if(num[i]>num[i+1]){
                     flag=1;
                     break;
                 }
                 else{
                     num[i+1]-=num[i];
                     num[i]=0;
                 }
             }
             if(flag==1) cout<<"no"<<endl;
             if(flag==0) cout<<"yes"<<endl;
       }
}

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>



#define endl '\n'

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



using namespace std;

void debug() { std::cout << "\n"; fflush(stdout); }

template<class T, class... Ts>

void debug(T arg, Ts &... args) {

std::cout << arg << ' ';

debug(args...);

}



int main()

{

turbo;

long long tt; cin >> tt;

while (tt--)

{

int n; cin >> n;

vector<int> a(n);

for (auto& x : a)

cin >> x;



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

{

int mn = min(a[i], a[i -1]);

a[i - 1] -= mn;

a[i] -= mn;

}



bool can = true;

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

{

if (a[i - 1] > a[i])

{

can = false;

break;

}

}

cout << (can ? "yes" : "no") << endl;

}

}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
using namespace std;

int main(){
    int t, n;
    long long sum, sum2;
    long long a[50];

    cin >> t;
    while (t--){
        cin >> n;
        for(int i=0; i<n; i++) cin >> a[i];

        sum = 0;
        for(int i=0; i<n; i++) sum += a[i];

        while (n>1){
            n--;
            for(int i=0; i<n; i++) a[i] = a[i+1] - a[i];
            
            sum2 = 0;
            for(int i=0; i<n; i++) sum2 += a[i];

            sum = max(sum, abs(sum2));
        }

        cout << sum << endl;
    }
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#ifdef MY_LOCAL_TEST
#include "debug.h"
#define debug(x) cerr << #x << " = "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
inline int nxt() { int x; cin >> x; return x; }
inline ll nxtll() { ll x; cin >> x; return x; }
inline string nxts() { string s; cin >> s; return s; }
void FastIO(string file = "") {
  cin.tie(nullptr)->sync_with_stdio(false);
#ifdef MY_LOCAL_TEST
  auto err_file = freopen("error.txt", "w", stderr);
  if (!err_file) {
    cerr << "can not open file"; exit(1);
  }
#endif
  if (file.empty()) return;
  auto in_file = freopen((file+".in").c_str(), "r", stdin);
  auto out_file = freopen((file+".out").c_str(), "w", stdout);
  if (!(in_file && out_file)) {
    cerr << "can not open file"; exit(1);
  }
}

constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = 1e9+7;

void solve() {
  int n = nxt();
  vector<ll> arr(n);
  generate(all(arr), nxtll);
  if (n == 1) {
    cout << arr[0] << "\n";
    return;
  }
  ll ans = -1e18;
  for (int i = 0, now = n; i < n; ++i, --now) {
    ll sum = 0;
    for (int i = 0; i < now; ++i) sum += arr[i];
    if (i == 0) ans = max(ans, sum);
    else ans = max(ans, abs(sum));
    for (int i = 0; i < now-1; ++i) arr[i] = arr[i+1]-arr[i];
  }
  cout << ans << "\n";
}

int main(void) {
  FastIO(""); int tc = 1; cin >> tc;
  for (int test = 1; test <= tc; ++test) { debug(test); solve(); }
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 124 ms):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;

void tc () {
    ll n;
    cin >> n;
    vll ve(n);
    for (ll &i : ve) cin >> i;
    ll j = 0;
    for (ll i = 1; i < n; i++) {
        if (ve[i-1] > ve[i]) j = i;
    }
    if (j == 0) { // all done
        cout << "YES\n";
        return;
    }
    auto fop = [&](ll i) {
        ll minN = min(ve[i], ve[i+1]);
        ve[i] -= minN;
        ve[i+1] -= minN;
    };
    for (ll i = 0; i < j; i++) {
        fop(i);
    }
    cout << (is_sorted(ve.begin(), ve.end()) ? "YES" : "NO") << '\n';
}

int main () {
    cin.tie(nullptr) -> sync_with_stdio(false);
    ll T; cin >> T; while (T--) { tc(); }
    return 0;
}

Solution 2 (runtime: 109 ms):
#include<bits/stdc++.h>

using namespace std;

void opp(int &i,int &j){

int k=min(i,j);

i-=k;

j-=k;

}

int can3be(vector<int> &v,int i){

int i1=v[i],j1=v[i+1],k1=v[i+2];

int i2=v[i],j2=v[i+1],k2=v[i+2];

opp(i1,j1);opp(j1,k1);

opp(j2,k2);opp(i2,j2);

if(i1<=j1&&j1<=k1){

opp(v[i],v[i+1]);opp(v[i+1],v[i+2]);

return 1;

}

if(i2<=j2&&j2<=k2){

opp(v[i+1],v[i+2]);opp(v[i],v[i+1]);

return 1;

}

return 0;

}

int main(){

ios_base::sync_with_stdio(0);cin.tie(0);

int t;

cin>>t;

while(t--){

int n;

cin>>n;

vector<int> v(n);

int flag=1;

for(auto &i:v) cin>>i;

if(n==2){

if(v[0]<=v[1]) cout<<"YES"<<"\n";

else cout<<"NO"<<"\n";

}

else{

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

flag = can3be(v,i);

if(flag==0) break;

}

if(flag) cout<<"YES"<<"\n";

else cout<<"NO"<<"\n";

}

}

}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 171 ms):
#include<bits/stdc++.h>

using namespace std;

#define ll long long 

#define pb push_back





int main()

{

  int t;

  cin>>t;

  while(t){

    int n, l, r;

    cin>>n>>l>>r;

    vector<int> arr(n);

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

      cin>>arr[i];

    }

   vector<int> left;

   vector<int> mid;

   vector<int> right;

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

    left.push_back(arr[i]);

   }

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

    mid.push_back(arr[i]);

   }

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

    right.push_back(arr[i]);

   }

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

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

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

    long long  sum = 0;

    for(auto it: mid){

      sum+=it;

    }



    long long ans = sum, prefixLeft=0, prefixRight = 0, prefixMid = 0;

    for(int i=0, j=mid.size()-1;i<mid.size();i++, j--) {

      prefixMid += mid[j];

      prefixRight += right.size()>i ? right[i] : mid[j];

      prefixLeft += left.size()>i ? left[i] : mid[j];

      ans = min(ans, sum + prefixRight - prefixMid);

      ans = min(ans, sum + prefixLeft - prefixMid);

    }



    cout<<ans<<endl;

    t--;

  }

  return 0;

}

Solution 2 (runtime: 93 ms):
//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(i>=l && i<=n)b.push_back(x);

            if(i<=r && i>=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;

}