ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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



using namespace std;



#define endl "\n"

#define int long long



void s1() {

    int n; cin >> n;

    vector<int> a(n);



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

        cin >> a[i];

    }



    if (a[0] > a[1]) {

        cout << "NO" << endl;

        return;

    }



    bool flag = true;

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

        if (a[i] > a[i + 1]) {

            flag = false;

            break;

        }

    }



    if (flag) {

        cout << "YES" << endl;

        return;

    }



    int sdd = 0, dup = a[0];

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

        if (a[i] != dup) {

            sdd = i - 1;

            break;

        }

    }



    if (sdd > 0) sdd--;

    // if (sdd != 0 && a[sdd] > a[sdd + 1]) {

    //     sdd++;

    // }



    // cerr << sdd << endl;



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

        if (a[i] > a[i + 1]) {

            // cout << i << endl;

            cout << "NO" << endl;

            return;

        }



        int temp = min(a[i], a[i + 1]);

        a[i] -= temp;

        a[i + 1] -= temp;

        // cout << a[i] << " " << a[i + 1] << endl;

    }



    cout << "YES" << endl;

    return;

}



signed main() {

    ios::sync_with_stdio(0);

    cin.tie(0);



    int t; cin >> t;

    while (t--) {

        s1();

    }



    // s1();



    return 0;

}

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



using namespace std;



#define endl "\n"

#define int long long



void s1() {

    int n; cin >> n;

    vector<int> a(n);



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

        cin >> a[i];

    }



    if (a[0] > a[1]) {

        cout << "NO" << endl;

        return;

    }



    bool flag = true;

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

        if (a[i] > a[i + 1]) {

            flag = false;

            break;

        }

    }



    if (flag) {

        cout << "YES" << endl;

        return;

    }



    int sdd = 0, dup = a[0];

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

        if (a[i] != dup) {

            sdd = i - 1;

            break;

        }

    }



    if (sdd > 0 && sdd % 2 == 1) sdd--;

    

    // if (sdd != 0 && a[sdd] > a[sdd + 1]) {

    //     sdd++;

    // }



    // cerr << sdd << endl;



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

        if (a[i] > a[i + 1]) {

            // cout << i << endl;

            cout << "NO" << endl;

            return;

        }



        int temp = min(a[i], a[i + 1]);

        a[i] -= temp;

        a[i + 1] -= temp;

        // cout << a[i] << " " << a[i + 1] << endl;

    }



    cout << "YES" << endl;

    return;

}



signed main() {

    ios::sync_with_stdio(0);

    cin.tie(0);



    int t; cin >> t;

    while (t--) {

        s1();

    }



    // s1();



    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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



using namespace std;



#define endl "\n"

#define int long long



void s1() {

    int n; cin >> n;

    vector<int> a(n);



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

        cin >> a[i];

    }



    if (a[0] > a[1]) {

        cout << "NO" << endl;

        return;

    }



    bool flag = true;

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

        if (a[i] > a[i + 1]) {

            flag = false;

            break;

        }

    }



    if (flag) {

        cout << "YES" << endl;

        return;

    }



    int sdd = 0, dup = a[0];

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

        if (a[i] != dup) {

            sdd = i - 1;

            break;

        }

    }



    // if (sdd != 0 && a[sdd] > a[sdd + 1]) {

    //     sdd++;

    // }



    // cerr << sdd << endl;



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

        if (a[i] > a[i + 1]) {

            // cout << i << endl;

            cout << "NO" << endl;

            return;

        }



        int temp = min(a[i], a[i + 1]);

        a[i] -= temp;

        a[i + 1] -= temp;

        // cout << a[i] << " " << a[i + 1] << endl;

    }



    cout << "YES" << endl;

    return;

}



signed main() {

    ios::sync_with_stdio(0);

    cin.tie(0);



    int t; cin >> t;

    while (t--) {

        s1();

    }



    // s1();



    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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



using namespace std;



#define endl "\n"

#define int long long



void s1() {

    int n; cin >> n;

    vector<int> a(n);



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

        cin >> a[i];

    }



    if (a[0] > a[1]) {

        cout << "NO" << endl;

        return;

    }



    bool flag = true;

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

        if (a[i] > a[i + 1]) {

            flag = false;

            break;

        }

    }



    if (flag) {

        cout << "YES" << endl;

        return;

    }



    int sdd = 0, dup = a[0];

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

        if (a[i] != dup) {

            sdd = i - 1;

            break;

        }

    }



    // if (sdd != 0 && a[sdd] > a[sdd + 1]) {

    //     sdd++;

    // }



    // cerr << sdd << endl;



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

        if (a[i] > a[i + 1]) {

            // cout << i << endl;

            cout << "NO" << endl;

            return;

        }



        int temp = min(a[i], a[i + 1]);

        a[i] -= temp;

        a[i + 1] -= temp;

        // cout << a[i] << " " << a[i + 1] << endl;

    }



    cout << "YES" << endl;

    return;

}



signed main() {

    ios::sync_with_stdio(0);

    cin.tie(0);



    int t; cin >> t;

    while (t--) {

        s1();

    }



    // s1();



    return 0;

}

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



using namespace std;



#define endl "\n"

#define int long long



void s1() {

    int n; cin >> n;

    vector<int> a(n);



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

        cin >> a[i];

    }



    if (a[0] > a[1]) {

        cout << "NO" << endl;

        return;

    }



    bool flag = true;

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

        if (a[i] > a[i + 1]) {

            flag = false;

            break;

        }

    }



    if (flag) {

        cout << "YES" << endl;

        return;

    }



    int sdd = 0, dup = a[0];

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

        if (a[i] != dup) {

            sdd = i - 1;

            break;

        }

    }



    if (sdd > 0) sdd--;

    // if (sdd != 0 && a[sdd] > a[sdd + 1]) {

    //     sdd++;

    // }



    // cerr << sdd << endl;



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

        if (a[i] > a[i + 1]) {

            // cout << i << endl;

            cout << "NO" << endl;

            return;

        }



        int temp = min(a[i], a[i + 1]);

        a[i] -= temp;

        a[i + 1] -= temp;

        // cout << a[i] << " " << a[i + 1] << endl;

    }



    cout << "YES" << endl;

    return;

}



signed main() {

    ios::sync_with_stdio(0);

    cin.tie(0);



    int t; cin >> t;

    while (t--) {

        s1();

    }



    // s1();



    return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

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

using namespace std;

const long long mod = 1e9 + 7;
const int MaxN = 30 + 5;

long long l, r;

void Inp()
{
    cin >> l >> r;
}

void Exc()
{
    int p = 0;
    for (int x = 31; x >= 0; x--)
    {
        if (((l >> x) & 1) != ((r >> x) & 1))
        {
            p = x;
            break;
        }
    }
    l &= ((1ll << (p + 1)) - 1);
    r &= ((1ll << (p + 1)) - 1);
    long long b = (1ll << p) - 1;
    if (l == b)
    {
        cout << b + 1 << " " << b + 2 << " " << b << "\n";
    }
    else
    {
        cout << b + 1 << " " << b << " " << b - 1 << "\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test = 1;
    cin >> test;
    for (int x = 1; x <= test; x++)
    {
        Inp();
        Exc();
    }
    return 0;
}


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

using namespace std;

const long long mod = 1e9 + 7;
const int MaxN = 30 + 5;

long long l, r;

void Inp()
{
    cin >> l >> r;
}

void Exc()
{
    int p = 0;
    long long cur = 0;
    for (int x = 31; x >= 0; x--)
    {
        if (((l >> x) & 1) != ((r >> x) & 1))
        {
            p = x;
            break;
        }
        else
        {
            cur ^= (l & (1 << x));
        }
    }
    l &= ((1ll << (p + 1)) - 1);
    r &= ((1ll << (p + 1)) - 1);
    //cout << l << " " << r << "\n";
    long long b = (1ll << p) - 1;
    if (l == b)
    {
        cout << ((b + 1) ^ cur) << " " << ((b + 2) ^ cur) << " " << (b ^ cur) << "\n";
    }
    else
    {
        cout << ((b + 1) ^ cur) << " " << (b ^ cur) << " " << ((b - 1) ^ cur) << "\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test = 1;
    cin >> test;
    for (int x = 1; x <= test; x++)
    {
        Inp();
        Exc();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


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

using namespace std;

const long long mod = 1e9 + 7;
const int MaxN = 30 + 5;

long long l, r;

void Inp()
{
    cin >> l >> r;
}

struct State
{
    long long a, b, c;

    State() = default;

    State(long long _a, long long _b, long long _c)
    {
        a = _a;
        b = _b;
        c = _c;
    }

    bool operator < (const State& other) const
    {
        if (this->a == other.a)
        {
            if (this->b == other.b)
            {
                return this->c < other.c;
            }
            return this->b < other.b;
        }
        return this->a < other.a;
    }
};

long long F[8][8][MaxN];
State track[8][8][MaxN];

pair<long long, State> DPDigit(int i, int maskl, int maskr)
{
    if (i < 0)
    {
        return make_pair(0, State(0, 0, 0));
    }
    if (F[maskl][maskr][i] != -1)
    {
        return make_pair(F[maskl][maskr][i], track[maskl][maskr][i]);
    }
    F[maskl][maskr][i] = 0;
    pair<long long, State> res = make_pair(0, State(0, 0, 0));
    int bitl = (l >> i) & 1, bitr = (r >> i) & 1;
    for (int x = 0; x < 2; x++)
    {
        for (int y = 0; y < 2; y++)
        {
            for (int z = 0; z < 2; z++)
            {
                if ((((maskl & 1) || x >= bitl) && ((maskr & 1) || (x <= bitr)))
                    && (((maskl & 2) || y >= bitl) && ((maskr & 2) || (y <= bitr)))
                    && (((maskl & 4) || z >= bitl) && ((maskr & 4) || (z <= bitr))))
                {
                    int newl = (((maskl | (x > bitl)) | ((y > bitl) << 1)) | ((z > bitl) << 2));
                    int newr = (((maskr | (x < bitr)) | ((y < bitr) << 1)) | ((z < bitr) << 2));
                    pair<long long, State> p = DPDigit(i - 1, newl, newr);
                    long long cur = p.first + ((x ^ y) << i) + ((y ^ z) << i) + ((z ^ x) << i);
                    State now(p.second.a ^ (x << i), p.second.b ^ (y << i), p.second.c ^ (z << i));
                    res = max(res, make_pair(cur, now));
                }
            }
        }
    }
    F[maskl][maskr][i] = res.first;
    track[maskl][maskr][i] = res.second;
    return res;
}

void Exc()
{
    memset(F, -1, sizeof(F));
    pair<long long, State> res =  DPDigit(31, 0, 0);
    cout << res.second.a << " " << res.second.b << " " << res.second.c << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test = 1;
    cin >> test;
    for (int x = 1; x <= test; x++)
    {
        Inp();
        Exc();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


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

using namespace std;



#define ll long long

#define pb push_back

#define vint vector<int>

#define vlong vector<long long>

#define traverse(n) for(int i=0;i<(n.size());i++)

#define yes cout<<"YES"<<endl

#define no cout<<"NO"<<endl

#define rev(arr) reverse(arr.begin(),arr.end())

#define srt(arr) sort(arr.begin(),arr.end())



// map in descending order  map<int,int,greater<int>>mpp 

// max-heap--> priority_queue<int>pq; -->arranged in descending 

// min-heap --> priority_queue<int,vector<int>,greater<int>>pq -->arrange in ascending 



ll log_a_base_b(ll a, ll b){return log2(a) / log2(b);}



ll ncr(ll n,ll r){

    ll result = 1;

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

        result = result * (n - r + i) / i;

    }

    return result;

}



ll lcm(ll a, ll b) {

  return (a / __gcd(a, b)) * b;

}

int main(){

    int t;

    cin>>t;

    while(t--){

       int n,l,r;

       cin>>n>>l>>r;

       l--;

       r--;

       vector<int> arr(n,0);

       vector<int> left(l+1);

       vector<int>mid(r-l+2);

       vector<int> right(n-r);

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

        cin>>left[i];

       }

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

        cin>>mid[i];

       }

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

         cin>>right[i];

       }

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

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

     rev(mid);

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

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

         if(i<left.size()&&i<right.size()){

             mid[i]=min(min(left[i],right[i]),mid[i]);

         }else if(i<left.size()){

            mid[i]=min(left[i],mid[i]);

         }else if(i<right.size()){

            mid[i]=min(right[i],mid[i]);

         }

      }

      ll sum=0;

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

          sum+=(ll)mid[i];

      }

      cout<<sum<<endl;



     

    }

}
Problem: 2061D - Kevin and Numbers
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
#define mod 1000000007

void solve()
{
    int n, m;
    cin >> n >> m;
    priority_queue<int> pq1, pq2;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        pq1.push(x);
    }
    for (int i = 0; i < m; i++)
    {
        int x;
        cin >> x;
        pq2.push(x);
    }
    int count = 0;
    while (!pq1.empty() && !pq2.empty() && count <= n - m)
    {
        int num1 = pq1.top();
        int num2 = pq2.top();
        pq1.pop();
        pq2.pop();
        // cout << num1 << " " << num2 << endl;
        if (num1 == num2)
            continue;
        else
        {
            count++;
            if (num2 % 2)
            {
                pq2.push(num2 / 2);
                pq2.push((num2 + 1) / 2);
            }
            else
            {
                pq2.push(num2 / 2);
                pq2.push(num2 / 2);
            }
            pq1.push(num1);
        }
    }
    if (pq1.empty() && pq2.empty())
    {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
}
#undef int
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
// https://codeforces.com/problemset/problem/2057/B

#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;

int solve(vector<int>& arr, int n, int k){
    unordered_map<int, int> freq;

    for (int i: arr) freq[i]++;

    vector<pair<int, int>> temp;  // {freq, element}
    for (auto x: freq) temp.push_back({x.second, x.first});
    sort(temp.begin(), temp.end());

    int i = 0;
    while (i < temp.size() - 1 && temp[i].first <= k){
        k = k - temp[i].first;
        i++;
    }

    return temp.size() - i;
}

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

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

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

        cout << solve(arr, n, k) << endl;
    }
}

Submission (verdict: Time limit exceeded on test 14):
// https://codeforces.com/problemset/problem/2057/B

#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;

int solve(vector<int>& arr, int n, int k){
    unordered_map<int, int> freq;

    for (int i: arr) freq[i]++;

    vector<pair<int, int>> temp;  // {freq, element}
    for (auto x: freq) temp.push_back({x.second, x.first});
    sort(temp.begin(), temp.end());

    int i = 0;
    while (i < temp.size() - 1 && temp[i].first <= k){
        k = k - temp[i].first;
        i++;
    }

    return temp.size() - i;
}

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

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

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

        cout << solve(arr, n, k) << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 14):
// https://codeforces.com/problemset/problem/2057/B

#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;

int solve(vector<int>& arr, int n, int k){
    unordered_map<int, int> freq;

    for (int i: arr) freq[i]++;

    vector<pair<int, int>> temp;  // {freq, element}
    for (auto x: freq) temp.push_back({x.second, x.first});
    sort(temp.begin(), temp.end());

    int i = 0;
    while (i < temp.size() - 1 && temp[i].first <= k){
        k = k - temp[i].first;
        i++;
    }

    return temp.size() - i;
}

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

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

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

        cout << solve(arr, n, k) << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
// https://codeforces.com/problemset/problem/2057/B

#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;

int solve(vector<int>& arr, int n, int k){
    unordered_map<int, int> freq;

    for (int i: arr) freq[i]++;

    vector<pair<int, int>> temp;  // {freq, element}
    for (auto x: freq) temp.push_back({x.second, x.first});
    sort(temp.begin(), temp.end());

    int i = 0;
    while (i < temp.size() - 1 && temp[i].first <= k){
        k = k - temp[i].first;
        i++;
    }

    return temp.size() - i;
}

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

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

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

        cout << solve(arr, n, k) << endl;
    }
}

Submission (verdict: Accepted):
// https://codeforces.com/problemset/problem/2057/B

#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;

int solve(vector<int>& arr, int n, int k){
    sort(arr.begin(), arr.end());
    std::vector<int> cnt = {1};

    for (int i = 1; i < n; i++) {
        if (arr[i] == arr[i - 1]) {
            cnt.back()++;
        } else {
            cnt.emplace_back(1);
        }
    }
    sort(cnt.begin(), cnt.end());

    int m = cnt.size();
    for (int i = 0; i < m - 1; i++) {
        if (cnt[i] > k) {
            return m - i;
        }
        k -= cnt[i];
    }

    return 1;
}

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

    int t;
    cin >> t;

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

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

        cout << solve(arr, n, k) << endl;
    }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;

#define ll long long

const int maxn=1e5+7;

char s[maxn];



void solve()

{

	scanf("%s",s+1);

	int n=strlen(s+1);

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

	{

		int res=-1;int now=s[i]-'0';

		for(int j=1;j<=9;j++)

		{

			int num=s[i+j]-'0';

			if(num-j>now)

			{

				res=j;now=num-j;

			}

		}

		if(res!=-1)

		{

			s[res+i]=s[res+i]-res;

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

		}

	}

	cout<<s+1<<endl;

	return ;

}

signed main()

{

	int t;cin>>t;

	while(t--) solve();

	return 0;

}









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

using namespace std;

#define ll long long

const int maxn=2e5+7;

char s[maxn];



void solve()

{

	scanf("%s",s+1);

	int n=strlen(s+1);

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

	{

		int res=-1;int now=s[i]-'0';

		for(int j=1;j<=9;j++)

		{

			int num=s[i+j]-'0';

			if(num-j>now)

			{

				res=j;now=num-j;

			}

		}

		if(res!=-1)

		{

			s[res+i]=s[res+i]-res;

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

		}

	}

	cout<<s+1<<endl;

	return ;

}

signed main()

{

	int t;cin>>t;

	while(t--) solve();

	return 0;

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

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

using namespace std;

#define ll long long

const int maxn=2e5+7;

char s[maxn];



void solve()

{

	scanf("%s",s+1);

	int n=strlen(s+1);

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

	{

		int res=-1;int now=s[i]-'0';

		for(int j=1;j<=9;j++)

		{

			int num=s[i+j]-'0';

			if(num-j>now)

			{

				res=j;now=num-j;

			}

		}

		if(res!=-1)

		{

			s[res+i]=s[res+i]-res;

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

		}

	}

	cout<<s+1<<endl;

	return ;

}

signed main()

{

	int t;cin>>t;

	while(t--) solve();

	return 0;

}









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

using namespace std;

#define ll long long

const int maxn=2e5+7;

char s[maxn];



void solve()

{

	scanf("%s",s+1);

	int n=strlen(s+1);

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

	{

		int res=-1;int now=s[i]-'0';

		for(int j=1;j<=9;j++)

		{

			if(i+j>n) continue;

			int num=s[i+j]-'0';

			if(num-j>now)

			{

				res=j;now=num-j;

			}

		}

		if(res!=-1)

		{

			s[res+i]=s[res+i]-res;

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

		}

	}

	cout<<s+1<<endl;

	return ;

}

signed main()

{

	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 2):
#include<bits/stdc++.h>

using namespace std;

#define ll long long

const int maxn=1e5+7;

char s[maxn];



void solve()

{

	scanf("%s",s+1);

	int n=strlen(s+1);

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

	{

		int res=-1;int now=s[i]-'0';

		for(int j=1;j<=9;j++)

		{

			int num=s[i+j]-'0';

			if(num-j>now)

			{

				res=j;now=num-j;

			}

		}

		if(res!=-1)

		{

			s[res+i]=s[res+i]-res;

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

		}

	}

	cout<<s+1<<endl;

	return ;

}

signed main()

{

	int t;cin>>t;

	while(t--) solve();

	return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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;

if(n < 2){

int dummy;

if(n == 1)

cin >> dummy;

cout << "YES" << endl;

continue;

}

vector<int> v(n);

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

cin >> v[i];

}

if(v[0] > v[1]){

cout << "NO" << endl;

continue;

}

int num = min(v[0], v[1]);

v[1] -= num;

int j = 1;

while(j + 1 < n && v[j+1] > v[j]){

v[j+1] -= v[j];

j++;

}

if(j != n - 1){

cout << "NO" << endl;

}

else{

cout << "YES" << endl;

}

}

return 0;

}



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

using namespace std;

int main(){

int t;

cin >> t;

while(t--){

int n;

cin >> n;

if(n < 2){

int dummy;

if(n == 1)

cin >> dummy;

cout << "YES" << endl;

continue;

}

vector<int> v(n) , u(n);

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

cin >> v[i];

}

int flag = 1 ;

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

{

v[i+1]-=v[i];

v[i]=0;

if(v[i+1]<0){

flag = 0 ;

break;

}

}

if(flag){

cout <<"YES" <<endl;

}

else{

cout << "NO" << endl;

}

}

}