import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//由题目可知,无论能量大与小,都满足 e = 2 * e - h[i];
//初始能量越大,最终的结果越大,要找到一个满足条件的最小值
//可以根据二分的向左找模板:
/*
if(check(mid)) r = mid;
else l = mid + 1;
*/
public class Main{
static int n;
static int N = 100010;
static int[] g = new int[N];
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
public static boolean check(int e) {
for(int i = 1;i <= n;i++) {
e = 2 * e - g[i];
if(e > 1e5) return true;
if(e < 0) return false;
}
return true;
}
public static void main(String[] args) throws IOException{
n = Integer.parseInt(in.readLine());
String[] data = in.readLine().split(" ");
for(int i = 1;i <= n;i ++) g[i] = Integer.parseInt(data[i - 1]);
int l = 0, r = 100000;
while(l < r) {
int mid = l + r >> 1;
if(check(mid)) r = mid;
else {
l = mid + 1;
}
}
System.out.println(l);
in.close();
}
}
可以再看看浮点数二分:浮点数二分
整数二分