#include <iostream>
#include <vector>
using namespace std;
int solution(vector<int> &A)
{
int n = A.size();
if(n == 0)
return 0;
int cnt = 0;
bool ok = true;
while(ok)
{
ok = false;
int i = 0;
while(i < n)
{
if(A[i] > 0)
{
while(i<n && A[i] > 0)
{
A[i]--;
if(A[i] > 0)
ok = true;
i++;
}
cnt++;
}
else
{
while(i < n && A[i]==0)
i++;
}
}
}
return cnt;
}
int main() {
vector<int> a;
a.push_back(1);
a.push_back(3);
a.push_back(2);
a.push_back(1);
a.push_back(2);
a.push_back(1);
a.push_back(5);
a.push_back(3);
a.push_back(3);
a.push_back(4);
a.push_back(2);
cout << solution(a) << endl;
getchar();
getchar();
}
天际线问题
最新推荐文章于 2024-09-04 17:30:44 发布