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

Previous submission (verdict: Time limit exceeded on test 6):
#include <iostream>
#include <vector>
#define int int64_t


using namespace std;

bool compare_vv(vector<char>& a, vector<char>& b) {
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] < b[i]) {
            return true;
        }
        if (a[i] > b[i]) {
            return false;
        }
    }
    return false;
}

void update (int pos, std::string& input_d) {
    int max_ = input_d[pos];
    int max_idx_ = pos;
    vector<vector<char>> to_compare;


 
    for (int swap_idx = pos; 
        (swap_idx < (pos + 9)) && (swap_idx < input_d.size());
        ++swap_idx) {

        vector<char> to_push;
        to_push.push_back(input_d[swap_idx] - (swap_idx - pos));

        for (int i = pos; (i < (pos + 9)) && (i < input_d.size()); ++i) {
            if (i == swap_idx) {
                continue;
            } else {
                to_push.push_back(input_d[i]);
            }
        }
        to_compare.push_back(to_push);
    }
    
    vector<char> max_v = to_compare[0];
    max_idx_ = 0;
    for (int i = 1; i < to_compare.size(); ++i) {
        if (compare_vv(max_v, to_compare[i])) {
            max_v = to_compare[i];
            max_idx_ = i;
        }
    }
    
    max_ = input_d[pos + max_idx_] - max_idx_;

    for (int i = pos+max_idx_; i > pos; --i) {
        input_d[i] = input_d[i - 1];
    }
    input_d[pos] = max_;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        string input_d;
        cin >> input_d;
        bool updated = true;
        while (updated) {
            updated = false;
            for (int i = 0; i + 1< input_d.size(); ++i)  {
                if (input_d[i] < input_d[i + 1] - 1) {
                    char x = input_d[i];
                    input_d[i] = input_d[i + 1] - 1;
                    input_d[i + 1] = x;
                    updated = true;
                    break;
                }; 
            }
        }
        cout << input_d << endl;
    }
}

Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#define int int64_t


using namespace std;

bool compare_vv(vector<char>& a, vector<char>& b) {
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] < b[i]) {
            return true;
        }
        if (a[i] > b[i]) {
            return false;
        }
    }
    return false;
}

void update (int pos, std::string& input_d) {
    int max_ = input_d[pos];
    int max_idx_ = pos;
    vector<vector<char>> to_compare;


 
    for (int swap_idx = pos; 
        (swap_idx < (pos + 9)) && (swap_idx < input_d.size());
        ++swap_idx) {

        vector<char> to_push;
        to_push.push_back(input_d[swap_idx] - (swap_idx - pos));

        for (int i = pos; (i < (pos + 9)) && (i < input_d.size()); ++i) {
            if (i == swap_idx) {
                continue;
            } else {
                to_push.push_back(input_d[i]);
            }
        }
        to_compare.push_back(to_push);
    }
    
    vector<char> max_v = to_compare[0];
    max_idx_ = 0;
    for (int i = 1; i < to_compare.size(); ++i) {
        if (compare_vv(max_v, to_compare[i])) {
            max_v = to_compare[i];
            max_idx_ = i;
        }
    }
    
    max_ = input_d[pos + max_idx_] - max_idx_;

    for (int i = pos+max_idx_; i > pos; --i) {
        input_d[i] = input_d[i - 1];
    }
    input_d[pos] = max_;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        string input_d;
        cin >> input_d;
       
        for (int i = 0; i + 1 < input_d.size(); ++i)  {
            if (input_d[i] < input_d[i + 1] - 1) {
                char x = input_d[i];
                input_d[i] = input_d[i + 1] - 1;
                input_d[i + 1] = x;
                i -= 2;
                i = i < -1 ? -1 : i;
            }; 
        }
        cout << input_d << endl;
    }
}