100712024-03-26 11:49:39Error42Számlexikoncpp17Wrong answer 50/1007ms3520 KiB
#include <cassert>
#include <climits>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

void solve() {
    // These are swapped everywhere!
    ll p, k;
    cin >> p >> k;

    string const ps = to_string(p);

    ll lo = 1;
    ll hi = 0;

    for (ll i = 0; i < ps.size(); i++) {
        hi = hi * 10 + (ps[i] - '0');

        k -= hi - lo + 1;

        lo *= 10;
    }

    assert(hi == p);

    if (k < 0) {
        cout << "0\n";
        return;
    }

    if (k == 0) {
        cout << p << "\n";
        return;
    }

    hi--;

    while (true) {
        hi = hi * 10 + 9;

        ll const added = hi - lo + 1;

        if (added == 0) {
            cout << "0\n";
            return;
        }

        if (added > k) {
            cout << lo - 1 + k << "\n";
            return;
        }

        k -= added;

        lo *= 10;
    }
}

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

    int t;
    cin >> t;

    while (t--)
        solve();
}
SubtaskSumTestVerdictTimeMemory
base50/100
1Accepted0/03ms1972 KiB
2Wrong answer0/07ms2244 KiB
3Accepted10/103ms2324 KiB
4Wrong answer0/103ms2388 KiB
5Wrong answer0/103ms2752 KiB
6Accepted10/102ms2680 KiB
7Accepted10/103ms2680 KiB
8Accepted10/103ms2900 KiB
9Accepted10/107ms3136 KiB
10Wrong answer0/107ms3236 KiB
11Wrong answer0/107ms3352 KiB
12Wrong answer0/106ms3520 KiB