-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuawei4.cpp
67 lines (61 loc) · 1.25 KB
/
huawei4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// see: https://blog.csdn.net/weixin_41937380/article/details/129139816
#include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int CalcMinIndent(vector<int>& nums)
{
int ret = 0;
while (true)
{
bool cont = false;
int min = INT_MAX;
int prev = 0, cur = 0;
for (; cur < nums.size(); ++cur)
{
if (nums[cur] > 0)
{
// record sth
if (!cont)
{
cont = true;
prev = cur;
}
if (nums[cur] < min)
{
min = nums[cur];
}
}
else if (cont)
{
break;
}
}
if (cont)
{
for (int i = prev; i < cur; ++i)
{
nums[i] -= min;
}
ret += min;
}
else break;
}
return ret;
}
int main()
{
int n, h;
cin >> n;
vector<int> nums;
nums.reserve(n);
while (n--)
{
cin >> h;
nums.push_back(h);
}
for (auto e : nums) cout << e << endl;
int ret = CalcMinIndent(nums);
cout << "ret=" << ret << endl;
return 0;
}