39292023-03-05 19:07:42zsomborHázszámokcpp17Accepted 100/1003ms5284 KiB
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

ll k, n = 0;
vector <ll> h(50, 1);
vector <ll> CNT(10, 0);
vector <ll> cnt(10, 0);
vector <ll> v(50, 0);

bool check(ll x) {
    fill(cnt.begin(), cnt.end(), 0);
    fill(v.begin(), v.end(), 0);
    for (ll i = 1; i <= n; i++) {
        if (x < h[i]) {
            cnt[0] += (x - h[i - 1] + 1) * i;
            break;
        }
        cnt[0] += (k - 1) * h[i - 1] * i;
    }
    for (ll i = n; i >= 0; i--) {
        v[i] = x / h[i];
        x %= h[i];
        if (v[i]) cnt[v[i]] += x + 1;
        for (int j = 1; j < v[i]; j++) cnt[j] += h[i];
        for (int j = 1; j < k; j++) cnt[j] += h[i] * i / k * v[i];
    }
    for (int i = 1; i < k; i++) cnt[0] -= cnt[i];
    for (int i = 0; i < k; i++) if (cnt[i] > CNT[i]) return false;
    return true;
}

int main()
{
    cin >> k;
    while (h[n] < 1e13) { n++; h[n] = k * h[n - 1]; }
    for (int i = 0; i < k; i++) cin >> CNT[i];
    ll l = 0, r = 1e13, m;
    while (r - l > 1) {
        m = (l + r) / 2;
        (check(m) ? l = m : r = m);
    }
    cout << l;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1876 KiB
2Accepted3ms2116 KiB
3Accepted3ms2168 KiB
subtask225/25
4Accepted3ms2304 KiB
5Accepted3ms2520 KiB
6Accepted3ms2732 KiB
7Accepted3ms2944 KiB
8Accepted3ms3196 KiB
9Accepted2ms3244 KiB
10Accepted3ms3272 KiB
11Accepted2ms3340 KiB
12Accepted3ms3584 KiB
13Accepted2ms3664 KiB
14Accepted2ms3668 KiB
15Accepted3ms3552 KiB
16Accepted3ms3672 KiB
17Accepted3ms3672 KiB
18Accepted3ms3796 KiB
19Accepted3ms3880 KiB
subtask310/10
20Accepted3ms3888 KiB
21Accepted2ms3772 KiB
22Accepted3ms3924 KiB
23Accepted3ms3956 KiB
24Accepted3ms3956 KiB
subtask415/15
25Accepted3ms3952 KiB
26Accepted3ms3848 KiB
27Accepted3ms3984 KiB
28Accepted3ms4096 KiB
29Accepted3ms4092 KiB
30Accepted3ms4212 KiB
31Accepted3ms4216 KiB
32Accepted3ms4340 KiB
33Accepted3ms4336 KiB
subtask520/20
34Accepted3ms4304 KiB
35Accepted3ms4416 KiB
36Accepted3ms4304 KiB
37Accepted3ms4392 KiB
38Accepted3ms4516 KiB
39Accepted3ms4480 KiB
40Accepted3ms4604 KiB
41Accepted3ms4484 KiB
42Accepted3ms4600 KiB
subtask630/30
43Accepted3ms4624 KiB
44Accepted3ms4852 KiB
45Accepted3ms4824 KiB
46Accepted3ms5040 KiB
47Accepted3ms5140 KiB
48Accepted3ms5140 KiB
49Accepted3ms5140 KiB
50Accepted3ms5260 KiB
51Accepted3ms5172 KiB
52Accepted3ms5168 KiB
53Accepted3ms5168 KiB
54Accepted3ms5168 KiB
55Accepted3ms5164 KiB
56Accepted3ms5160 KiB
57Accepted3ms5284 KiB
58Accepted2ms5284 KiB
59Accepted2ms5044 KiB
60Accepted3ms5048 KiB