100722024-03-26 11:53:19Error42Számlexikoncpp17Elfogadva 100/1007ms3680 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();
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base100/100
1Elfogadva0/03ms1832 KiB
2Elfogadva0/07ms2172 KiB
3Elfogadva10/103ms2264 KiB
4Elfogadva10/103ms2620 KiB
5Elfogadva10/103ms2572 KiB
6Elfogadva10/103ms2664 KiB
7Elfogadva10/102ms2752 KiB
8Elfogadva10/103ms2964 KiB
9Elfogadva10/107ms3332 KiB
10Elfogadva10/107ms3264 KiB
11Elfogadva10/107ms3392 KiB
12Elfogadva10/106ms3680 KiB