AcWing 730. 机器人跳跃问题
原题链接
中等
作者:
沙漠绿洲
,
2020-09-19 22:07:51
,
所有人可见
,
阅读 409
C++ 代码
#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int h[N];
int n, maxm = -1;
bool check(int ans){
for(int i = 1; i <= n; ++ i){
ans += (ans - h[i]);
if(ans < 0) return false;
if(ans > maxm) return true;
}
return true;
}
int main()
{
cin >> n;
for(int i = 1; i <= n; ++ i){
scanf("%d", &h[i]);
maxm = max(maxm, h[i]);
}
int l = 0, r = maxm;
while(l < r){
int mid = l + r >> 1;
if(check(mid)) r = mid;
else l = mid + 1;
}
cout << l << endl;
return 0;
}