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