#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;
for(int p=1;p<=n;p*=K){
int xx=n/(p*K)*p+(i==0?0:min(max(n%(p*K)-p*i,0ll),p));
x+=xx;
}
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;
}
}
cout<<h-1<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1832 KiB | ||||
2 | Accepted | 3ms | 2056 KiB | ||||
3 | Wrong answer | 3ms | 2244 KiB | ||||
subtask2 | 0/25 | ||||||
4 | Wrong answer | 3ms | 2452 KiB | ||||
5 | Wrong answer | 3ms | 2668 KiB | ||||
6 | Wrong answer | 3ms | 2872 KiB | ||||
7 | Wrong answer | 3ms | 3232 KiB | ||||
8 | Accepted | 3ms | 3408 KiB | ||||
9 | Accepted | 3ms | 3400 KiB | ||||
10 | Wrong answer | 3ms | 3372 KiB | ||||
11 | Wrong answer | 3ms | 3740 KiB | ||||
12 | Accepted | 3ms | 3692 KiB | ||||
13 | Wrong answer | 3ms | 3720 KiB | ||||
14 | Accepted | 3ms | 3796 KiB | ||||
15 | Wrong answer | 3ms | 3876 KiB | ||||
16 | Wrong answer | 3ms | 3868 KiB | ||||
17 | Wrong answer | 3ms | 3972 KiB | ||||
18 | Wrong answer | 3ms | 3876 KiB | ||||
19 | Wrong answer | 3ms | 3872 KiB | ||||
subtask3 | 10/10 | ||||||
20 | Accepted | 3ms | 3872 KiB | ||||
21 | Accepted | 3ms | 3872 KiB | ||||
22 | Accepted | 3ms | 4096 KiB | ||||
23 | Accepted | 3ms | 4104 KiB | ||||
24 | Accepted | 3ms | 4104 KiB | ||||
subtask4 | 15/15 | ||||||
25 | Accepted | 3ms | 4100 KiB | ||||
26 | Accepted | 3ms | 4208 KiB | ||||
27 | Accepted | 3ms | 4216 KiB | ||||
28 | Accepted | 3ms | 4088 KiB | ||||
29 | Accepted | 3ms | 4196 KiB | ||||
30 | Accepted | 3ms | 4328 KiB | ||||
31 | Accepted | 3ms | 4428 KiB | ||||
32 | Accepted | 3ms | 4432 KiB | ||||
33 | Accepted | 3ms | 4520 KiB | ||||
subtask5 | 0/20 | ||||||
34 | Accepted | 3ms | 4516 KiB | ||||
35 | Accepted | 3ms | 4516 KiB | ||||
36 | Wrong answer | 3ms | 4528 KiB | ||||
37 | Wrong answer | 3ms | 4624 KiB | ||||
38 | Accepted | 3ms | 4628 KiB | ||||
39 | Accepted | 3ms | 4628 KiB | ||||
40 | Accepted | 3ms | 4728 KiB | ||||
41 | Accepted | 3ms | 4880 KiB | ||||
42 | Wrong answer | 3ms | 4836 KiB | ||||
subtask6 | 0/30 | ||||||
43 | Wrong answer | 3ms | 4864 KiB | ||||
44 | Wrong answer | 3ms | 4872 KiB | ||||
45 | Wrong answer | 3ms | 4920 KiB | ||||
46 | Wrong answer | 3ms | 5036 KiB | ||||
47 | Wrong answer | 3ms | 4744 KiB | ||||
48 | Wrong answer | 3ms | 4748 KiB | ||||
49 | Wrong answer | 3ms | 4852 KiB | ||||
50 | Wrong answer | 3ms | 4976 KiB | ||||
51 | Accepted | 3ms | 4976 KiB | ||||
52 | Wrong answer | 3ms | 5048 KiB | ||||
53 | Wrong answer | 3ms | 5228 KiB | ||||
54 | Wrong answer | 3ms | 5236 KiB | ||||
55 | Wrong answer | 3ms | 5092 KiB | ||||
56 | Wrong answer | 3ms | 5104 KiB | ||||
57 | Wrong answer | 3ms | 5192 KiB | ||||
58 | Accepted | 3ms | 5100 KiB | ||||
59 | Wrong answer | 3ms | 5096 KiB | ||||
60 | Wrong answer | 3ms | 5128 KiB |