#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
ll k, n = 0;
vector <ll> h(51, 1);
vector <ll> CNT(10, 0);
vector <ll> cnt(10, 0);
vector <ll> v(51, 0);
bool check(ll x) {
fill(cnt.begin(), cnt.end(), 0);
fill(v.begin(), v.end(), 0);
for (int i = 1; i <= n; i++) {
if (x < h[i]-1) {
cnt[0] += ((x + 1) % h[i - 1]) * i;
break;
}
cnt[0] += (k - 1) * h[i - 1] * i;
}
for (int 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] < 1e15) { n++; h[n] = k * h[n - 1]; }
for (int i = 0; i < k; i++) cin >> CNT[i];
ll l = 0, r = 1e15, m;
while (r - l > 1) {
m = (l + r) / 2;
(check(m) ? l = m : r = m);
}
cout << l;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1876 KiB | ||||
2 | Accepted | 3ms | 2120 KiB | ||||
3 | Accepted | 3ms | 2364 KiB | ||||
subtask2 | 0/25 | ||||||
4 | Accepted | 3ms | 2416 KiB | ||||
5 | Accepted | 3ms | 2656 KiB | ||||
6 | Accepted | 3ms | 2708 KiB | ||||
7 | Accepted | 3ms | 2952 KiB | ||||
8 | Accepted | 3ms | 3128 KiB | ||||
9 | Accepted | 3ms | 3244 KiB | ||||
10 | Accepted | 3ms | 3336 KiB | ||||
11 | Accepted | 3ms | 3336 KiB | ||||
12 | Accepted | 3ms | 3344 KiB | ||||
13 | Accepted | 3ms | 3340 KiB | ||||
14 | Accepted | 3ms | 3432 KiB | ||||
15 | Wrong answer | 3ms | 3424 KiB | ||||
16 | Accepted | 3ms | 3440 KiB | ||||
17 | Accepted | 3ms | 3656 KiB | ||||
18 | Accepted | 3ms | 3736 KiB | ||||
19 | Accepted | 3ms | 3876 KiB | ||||
subtask3 | 10/10 | ||||||
20 | Accepted | 3ms | 3952 KiB | ||||
21 | Accepted | 3ms | 3952 KiB | ||||
22 | Accepted | 3ms | 3948 KiB | ||||
23 | Accepted | 3ms | 3948 KiB | ||||
24 | Accepted | 2ms | 3956 KiB | ||||
subtask4 | 15/15 | ||||||
25 | Accepted | 3ms | 4192 KiB | ||||
26 | Accepted | 3ms | 4300 KiB | ||||
27 | Accepted | 3ms | 4404 KiB | ||||
28 | Accepted | 3ms | 4380 KiB | ||||
29 | Accepted | 3ms | 4504 KiB | ||||
30 | Accepted | 2ms | 4584 KiB | ||||
31 | Accepted | 3ms | 4588 KiB | ||||
32 | Accepted | 3ms | 4716 KiB | ||||
33 | Accepted | 3ms | 4800 KiB | ||||
subtask5 | 0/20 | ||||||
34 | Accepted | 3ms | 4800 KiB | ||||
35 | Accepted | 3ms | 4912 KiB | ||||
36 | Wrong answer | 3ms | 4912 KiB | ||||
37 | Accepted | 3ms | 5160 KiB | ||||
38 | Accepted | 3ms | 5244 KiB | ||||
39 | Accepted | 3ms | 5248 KiB | ||||
40 | Accepted | 3ms | 5256 KiB | ||||
41 | Accepted | 3ms | 5376 KiB | ||||
42 | Accepted | 3ms | 5340 KiB | ||||
subtask6 | 0/30 | ||||||
43 | Accepted | 3ms | 5364 KiB | ||||
44 | Accepted | 2ms | 5336 KiB | ||||
45 | Accepted | 3ms | 5368 KiB | ||||
46 | Accepted | 2ms | 5444 KiB | ||||
47 | Accepted | 3ms | 5336 KiB | ||||
48 | Wrong answer | 2ms | 5344 KiB | ||||
49 | Accepted | 2ms | 5224 KiB | ||||
50 | Accepted | 3ms | 5224 KiB | ||||
51 | Accepted | 3ms | 5336 KiB | ||||
52 | Accepted | 3ms | 5340 KiB | ||||
53 | Accepted | 3ms | 5336 KiB | ||||
54 | Accepted | 3ms | 5348 KiB | ||||
55 | Accepted | 2ms | 5348 KiB | ||||
56 | Accepted | 3ms | 5224 KiB | ||||
57 | Accepted | 3ms | 5340 KiB | ||||
58 | Accepted | 3ms | 5336 KiB | ||||
59 | Accepted | 3ms | 5348 KiB | ||||
60 | Accepted | 3ms | 5348 KiB |