#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 = 6, 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 | Wrong answer | 2ms | 2128 KiB | ||||
3 | Wrong answer | 2ms | 2336 KiB | ||||
subtask2 | 0/25 | ||||||
4 | Wrong answer | 2ms | 2488 KiB | ||||
5 | Wrong answer | 3ms | 2700 KiB | ||||
6 | Wrong answer | 3ms | 2912 KiB | ||||
7 | Wrong answer | 3ms | 3128 KiB | ||||
8 | Wrong answer | 2ms | 3244 KiB | ||||
9 | Wrong answer | 2ms | 3492 KiB | ||||
10 | Wrong answer | 2ms | 3716 KiB | ||||
11 | Wrong answer | 2ms | 3740 KiB | ||||
12 | Wrong answer | 2ms | 3752 KiB | ||||
13 | Wrong answer | 2ms | 3876 KiB | ||||
14 | Wrong answer | 2ms | 3748 KiB | ||||
15 | Wrong answer | 2ms | 3756 KiB | ||||
16 | Wrong answer | 2ms | 3756 KiB | ||||
17 | Wrong answer | 2ms | 3756 KiB | ||||
18 | Wrong answer | 3ms | 3752 KiB | ||||
19 | Wrong answer | 2ms | 3752 KiB | ||||
subtask3 | 0/10 | ||||||
20 | Wrong answer | 2ms | 3752 KiB | ||||
21 | Wrong answer | 3ms | 3868 KiB | ||||
22 | Wrong answer | 3ms | 3876 KiB | ||||
23 | Accepted | 3ms | 4092 KiB | ||||
24 | Wrong answer | 2ms | 4144 KiB | ||||
subtask4 | 0/15 | ||||||
25 | Wrong answer | 2ms | 4140 KiB | ||||
26 | Wrong answer | 3ms | 4272 KiB | ||||
27 | Wrong answer | 3ms | 4480 KiB | ||||
28 | Wrong answer | 2ms | 4564 KiB | ||||
29 | Wrong answer | 3ms | 4564 KiB | ||||
30 | Wrong answer | 3ms | 4568 KiB | ||||
31 | Wrong answer | 2ms | 4572 KiB | ||||
32 | Wrong answer | 3ms | 4580 KiB | ||||
33 | Wrong answer | 3ms | 4708 KiB | ||||
subtask5 | 0/20 | ||||||
34 | Wrong answer | 2ms | 4788 KiB | ||||
35 | Wrong answer | 3ms | 4784 KiB | ||||
36 | Wrong answer | 2ms | 4792 KiB | ||||
37 | Wrong answer | 2ms | 4784 KiB | ||||
38 | Wrong answer | 2ms | 4792 KiB | ||||
39 | Wrong answer | 3ms | 4788 KiB | ||||
40 | Wrong answer | 3ms | 4788 KiB | ||||
41 | Wrong answer | 2ms | 4788 KiB | ||||
42 | Wrong answer | 2ms | 4788 KiB | ||||
subtask6 | 0/30 | ||||||
43 | Wrong answer | 2ms | 4784 KiB | ||||
44 | Wrong answer | 2ms | 4784 KiB | ||||
45 | Wrong answer | 2ms | 4788 KiB | ||||
46 | Wrong answer | 2ms | 4816 KiB | ||||
47 | Wrong answer | 3ms | 4812 KiB | ||||
48 | Wrong answer | 2ms | 4804 KiB | ||||
49 | Wrong answer | 3ms | 4940 KiB | ||||
50 | Wrong answer | 3ms | 4948 KiB | ||||
51 | Wrong answer | 3ms | 4916 KiB | ||||
52 | Accepted | 3ms | 4940 KiB | ||||
53 | Wrong answer | 3ms | 5004 KiB | ||||
54 | Wrong answer | 3ms | 4900 KiB | ||||
55 | Wrong answer | 3ms | 4896 KiB | ||||
56 | Wrong answer | 3ms | 4892 KiB | ||||
57 | Wrong answer | 3ms | 4900 KiB | ||||
58 | Wrong answer | 3ms | 4896 KiB | ||||
59 | Wrong answer | 2ms | 4896 KiB | ||||
60 | Wrong answer | 3ms | 4896 KiB |