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
| #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=100010; int n; int h[N];
bool check(int e) { for(int i=1;i<=n;i++) { e=e*2-h[i]; if(e>=1e5) return true; if(e<0) return 0; } return true; }
int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&h[i]); int l=0,r=1e5; while(r>l){ int mid=l+r>>1; if(check(mid)) r=mid; else l=mid+1; } printf("%d\n",l); return 0; }
|