-
Notifications
You must be signed in to change notification settings - Fork 1
/
18185.cpp
46 lines (39 loc) · 896 Bytes
/
18185.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
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int one(vector<int> &a, int idx, int x) {
a[idx] -= x;
return 3 * x;
}
int two(vector<int> &a, int idx, int x) {
a[idx] -= x; a[idx+1] -= x;
return 5 * x;
}
int three(vector<int> &a, int idx, int x) {
a[idx] -= x; a[idx+1] -= x; a[idx+2] -= x;
return 7 * x;
}
void solve(void) {
int n; cin >> n;
vector<int> a(n+2, 0);
for (int i=0; i<n; i++) cin >> a[i];
int ans = 0;
for (int i=0; i<n; i++) {
if (a[i+1] > a[i+2]) {
ans += two(a, i, min(a[i], a[i+1] - a[i+2]));
ans += three(a, i, min({a[i], a[i+1], a[i+2]}));
} else {
ans += three(a, i, min({a[i], a[i+1], a[i+2]}));
ans += two(a, i, min(a[i], a[i+1]));
}
ans += one(a, i, a[i]);
}
cout << ans;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}