#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int K;
cin>>K;
vector<int>v(K);
for(int i=0;i<K;i++){
cin>>v[i];
}
v[0]++;
auto calc=[&](int n,int i)->int{
int x=0;
if(i>0){
for(int p=1;p<=n;p*=K){
x+=n/(p*K)*p;
x+=min(max(n%(p*K)-p*i,0ll),p);
}
}
else{
for(int p=1;p<=n;p*=K){
x+=max((n/(p*K)-1)*p,0ll);
if(n>=p*K){
x+=min(max(n%(p*K),0ll),p);
}
}
}
return x;
};
int l=1,h=1e17;
while(l<h){
int m=(l+h)/2;
int ok=1;
for(int i=0;i<K;i++){
ok&=calc(m+1,i)<=v[i];
}
if(ok){
l=m+1;
}
else{
h=m;
}
}
if(h==1e17)exit(1);
cout<<h-1<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1704 KiB | ||||
2 | Accepted | 3ms | 1860 KiB | ||||
3 | Accepted | 3ms | 2208 KiB | ||||
subtask2 | 0/25 | ||||||
4 | Accepted | 3ms | 2432 KiB | ||||
5 | Accepted | 3ms | 2528 KiB | ||||
6 | Accepted | 3ms | 2740 KiB | ||||
7 | Wrong answer | 3ms | 2932 KiB | ||||
8 | Accepted | 3ms | 3024 KiB | ||||
9 | Accepted | 3ms | 3148 KiB | ||||
10 | Accepted | 3ms | 3220 KiB | ||||
11 | Accepted | 3ms | 3220 KiB | ||||
12 | Accepted | 3ms | 3348 KiB | ||||
13 | Accepted | 3ms | 3712 KiB | ||||
14 | Accepted | 3ms | 3780 KiB | ||||
15 | Wrong answer | 3ms | 3792 KiB | ||||
16 | Accepted | 3ms | 3768 KiB | ||||
17 | Accepted | 3ms | 3900 KiB | ||||
18 | Accepted | 3ms | 4112 KiB | ||||
19 | Wrong answer | 3ms | 4208 KiB | ||||
subtask3 | 10/10 | ||||||
20 | Accepted | 3ms | 4208 KiB | ||||
21 | Accepted | 3ms | 4300 KiB | ||||
22 | Accepted | 3ms | 4300 KiB | ||||
23 | Accepted | 3ms | 4400 KiB | ||||
24 | Accepted | 3ms | 4432 KiB | ||||
subtask4 | 15/15 | ||||||
25 | Accepted | 3ms | 4408 KiB | ||||
26 | Accepted | 3ms | 4412 KiB | ||||
27 | Accepted | 3ms | 4404 KiB | ||||
28 | Accepted | 3ms | 4404 KiB | ||||
29 | Accepted | 3ms | 4508 KiB | ||||
30 | Accepted | 3ms | 4508 KiB | ||||
31 | Accepted | 3ms | 4512 KiB | ||||
32 | Accepted | 3ms | 4404 KiB | ||||
33 | Accepted | 3ms | 4532 KiB | ||||
subtask5 | 0/20 | ||||||
34 | Accepted | 3ms | 4620 KiB | ||||
35 | Accepted | 3ms | 4992 KiB | ||||
36 | Wrong answer | 3ms | 4768 KiB | ||||
37 | Wrong answer | 3ms | 4864 KiB | ||||
38 | Accepted | 3ms | 4864 KiB | ||||
39 | Accepted | 3ms | 4868 KiB | ||||
40 | Accepted | 3ms | 4836 KiB | ||||
41 | Accepted | 3ms | 4924 KiB | ||||
42 | Accepted | 3ms | 4840 KiB | ||||
subtask6 | 0/30 | ||||||
43 | Accepted | 3ms | 5092 KiB | ||||
44 | Accepted | 3ms | 4844 KiB | ||||
45 | Accepted | 3ms | 4848 KiB | ||||
46 | Accepted | 3ms | 4940 KiB | ||||
47 | Accepted | 3ms | 4936 KiB | ||||
48 | Wrong answer | 3ms | 4940 KiB | ||||
49 | Accepted | 3ms | 5084 KiB | ||||
50 | Accepted | 3ms | 5016 KiB | ||||
51 | Accepted | 3ms | 5108 KiB | ||||
52 | Wrong answer | 3ms | 5108 KiB | ||||
53 | Accepted | 3ms | 5104 KiB | ||||
54 | Accepted | 3ms | 5208 KiB | ||||
55 | Accepted | 3ms | 5112 KiB | ||||
56 | Accepted | 3ms | 4916 KiB | ||||
57 | Accepted | 3ms | 5012 KiB | ||||
58 | Accepted | 3ms | 4916 KiB | ||||
59 | Accepted | 3ms | 4920 KiB | ||||
60 | Wrong answer | 3ms | 5024 KiB |