52452023-04-23 18:46:34ZsofiaKeresztelyHázszámokcpp14Accepted 100/1003ms4792 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> lim;
int k;

vector<int> convert(ll n){
    vector<int> r;
    while (n){
        r.push_back(n % k);
        n /= k;
    }
    return r;
}

bool ok(ll m, vector<int> n){
    vector<ll> req(k, 0);
    ll power = 1;
    for (int i=0; i<n.size(); i++){
        ll quo = m / (power * k);
        for (int j=0; j<n[i]; j++){
            req[j] += power * (quo + 1);
        }
        req[n[i]] += m % power + 1;
        for (int j=n[i]; j<k; j++){
            req[j] += power * quo;
        }
        req[0] -= power;
        for (int j=0; j<k; j++){
            if (req[j] > lim[j]) return 0;
        }
        power *= k;
    }
    return 1;
}

int main()
{
    cin >> k;
    lim.resize(k);
    for (ll &x : lim){
        cin >> x;
    }
    ll l = 1, r = 1e13;
    while (l + 1 < r){
        ll m = (l + r) / 2;
        if (ok(m, convert(m))){
            l = m;
        }
        else{
            r = m;
        }
    }
    cout << l;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1684 KiB
2Accepted3ms1924 KiB
3Accepted3ms2012 KiB
subtask225/25
4Accepted3ms2152 KiB
5Accepted3ms2512 KiB
6Accepted3ms2596 KiB
7Accepted3ms2712 KiB
8Accepted3ms2776 KiB
9Accepted2ms2972 KiB
10Accepted3ms3216 KiB
11Accepted3ms3300 KiB
12Accepted3ms3396 KiB
13Accepted3ms3508 KiB
14Accepted3ms3508 KiB
15Accepted3ms3484 KiB
16Accepted3ms3716 KiB
17Accepted3ms3688 KiB
18Accepted3ms3824 KiB
19Accepted3ms4064 KiB
subtask310/10
20Accepted3ms4152 KiB
21Accepted3ms4152 KiB
22Accepted3ms4264 KiB
23Accepted3ms4120 KiB
24Accepted3ms4144 KiB
subtask415/15
25Accepted3ms4244 KiB
26Accepted3ms4348 KiB
27Accepted3ms4240 KiB
28Accepted3ms4232 KiB
29Accepted3ms4124 KiB
30Accepted3ms4124 KiB
31Accepted3ms4280 KiB
32Accepted3ms4268 KiB
33Accepted3ms4388 KiB
subtask520/20
34Accepted3ms4268 KiB
35Accepted3ms4520 KiB
36Accepted3ms4516 KiB
37Accepted3ms4488 KiB
38Accepted3ms4484 KiB
39Accepted3ms4508 KiB
40Accepted3ms4496 KiB
41Accepted3ms4484 KiB
42Accepted3ms4480 KiB
subtask630/30
43Accepted3ms4488 KiB
44Accepted3ms4484 KiB
45Accepted3ms4480 KiB
46Accepted3ms4604 KiB
47Accepted3ms4604 KiB
48Accepted3ms4600 KiB
49Accepted3ms4600 KiB
50Accepted3ms4480 KiB
51Accepted3ms4480 KiB
52Accepted3ms4484 KiB
53Accepted3ms4512 KiB
54Accepted3ms4484 KiB
55Accepted3ms4600 KiB
56Accepted3ms4548 KiB
57Accepted3ms4660 KiB
58Accepted3ms4792 KiB
59Accepted3ms4688 KiB
60Accepted3ms4712 KiB