题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include<iostream>
using namespace std;
const int N = 100010;
int h[N], n;
bool check(int e)
{
for (int i = 1; i <= n; i ++)
{
e = 2 * e - h[i];
if (e < 0) return false;
if (e > N) return true;
}
return true;
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++) cin >> h[i];
int l = h[0] / 2 + 1, r = 100000;
while(l < r)
{
int mid = l + r >> 1;
if (check(mid)) r = mid;
else l = mid + 1;
}
cout << r;
return 0;
}
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
//贪心;
#include<iostream>
using namespace std;
const int N = 100010;
int h[N], n;
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++) cin >> h[i];
int res = 0;
for (int i = n; i >= 1; i --)
{
res = (res + h[i] + 1) / 2;
}
cout << res;
return 0;
}