-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_number.cpp
More file actions
56 lines (53 loc) · 795 Bytes
/
binary_number.cpp
File metadata and controls
56 lines (53 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool isPossible(vector<ll>&v, ll target){
vector<ll>temp(v.size());
for(int i=0;i<v.size();i++){
temp[i]=v[i];
}
for(ll i=temp.size()-1;i>=0;i--){
if(temp[i]<target){
return false;
}
if(i>=2){
ll val = temp[i]-target;
ll diff = val / 3;
diff = min(diff, v[i]/3);
temp[i]-=3*diff;
temp[i-1]+=diff;
temp[i-2]+=2*diff;
}
}
return true;
}
void solve(){
ll x;
cin>>x;
vector<ll>v(x);
for(int i=0;i<x;i++){
cin>>v[i];
}
ll low=1;
ll high=1e18;
ll ans=low;
while(low<=high){
ll mid = low+(high-low)/2;
if(isPossible(v,mid)){
low=mid+1;
ans=max(ans,mid);
}
else{
high=mid-1;
}
}
cout<<ans<<endl;
}
int main(){
ll t;
cin>>t;
while(t--){
solve();
}
return 0;
}