#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] < 1e14) { 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1872 KiB | ||||
2 | Accepted | 3ms | 2116 KiB | ||||
3 | Accepted | 3ms | 2296 KiB | ||||
subtask2 | 0/25 | ||||||
4 | Accepted | 3ms | 2504 KiB | ||||
5 | Accepted | 3ms | 2720 KiB | ||||
6 | Accepted | 3ms | 2936 KiB | ||||
7 | Accepted | 3ms | 3020 KiB | ||||
8 | Accepted | 3ms | 3028 KiB | ||||
9 | Accepted | 3ms | 3024 KiB | ||||
10 | Accepted | 3ms | 3152 KiB | ||||
11 | Accepted | 3ms | 3404 KiB | ||||
12 | Accepted | 3ms | 3484 KiB | ||||
13 | Accepted | 3ms | 3620 KiB | ||||
14 | Accepted | 3ms | 3828 KiB | ||||
15 | Wrong answer | 3ms | 4076 KiB | ||||
16 | Accepted | 3ms | 4124 KiB | ||||
17 | Accepted | 3ms | 4252 KiB | ||||
18 | Accepted | 3ms | 4460 KiB | ||||
19 | Accepted | 3ms | 4580 KiB | ||||
subtask3 | 10/10 | ||||||
20 | Accepted | 3ms | 4704 KiB | ||||
21 | Accepted | 3ms | 4544 KiB | ||||
22 | Accepted | 3ms | 4512 KiB | ||||
23 | Accepted | 2ms | 4624 KiB | ||||
24 | Accepted | 3ms | 4760 KiB | ||||
subtask4 | 15/15 | ||||||
25 | Accepted | 3ms | 4784 KiB | ||||
26 | Accepted | 3ms | 5004 KiB | ||||
27 | Accepted | 3ms | 5008 KiB | ||||
28 | Accepted | 3ms | 5100 KiB | ||||
29 | Accepted | 3ms | 5096 KiB | ||||
30 | Accepted | 3ms | 5212 KiB | ||||
31 | Accepted | 3ms | 5096 KiB | ||||
32 | Accepted | 3ms | 4976 KiB | ||||
33 | Accepted | 3ms | 4976 KiB | ||||
subtask5 | 0/20 | ||||||
34 | Accepted | 3ms | 4968 KiB | ||||
35 | Accepted | 3ms | 4992 KiB | ||||
36 | Wrong answer | 3ms | 4976 KiB | ||||
37 | Accepted | 3ms | 4996 KiB | ||||
38 | Accepted | 3ms | 4984 KiB | ||||
39 | Accepted | 3ms | 4984 KiB | ||||
40 | Accepted | 3ms | 4976 KiB | ||||
41 | Accepted | 3ms | 5080 KiB | ||||
42 | Accepted | 3ms | 5208 KiB | ||||
subtask6 | 0/30 | ||||||
43 | Accepted | 3ms | 5292 KiB | ||||
44 | Accepted | 3ms | 5184 KiB | ||||
45 | Accepted | 3ms | 5208 KiB | ||||
46 | Accepted | 3ms | 5184 KiB | ||||
47 | Accepted | 3ms | 5180 KiB | ||||
48 | Wrong answer | 3ms | 5184 KiB | ||||
49 | Accepted | 3ms | 5296 KiB | ||||
50 | Accepted | 3ms | 5296 KiB | ||||
51 | Accepted | 3ms | 5308 KiB | ||||
52 | Accepted | 3ms | 5300 KiB | ||||
53 | Accepted | 3ms | 5308 KiB | ||||
54 | Accepted | 3ms | 5292 KiB | ||||
55 | Accepted | 2ms | 5292 KiB | ||||
56 | Accepted | 3ms | 5296 KiB | ||||
57 | Accepted | 3ms | 5412 KiB | ||||
58 | Accepted | 2ms | 5412 KiB | ||||
59 | Accepted | 3ms | 5200 KiB | ||||
60 | Accepted | 2ms | 5188 KiB |