-
Notifications
You must be signed in to change notification settings - Fork 0
/
18185.cpp
51 lines (41 loc) · 992 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
47
48
49
50
51
#include<iostream>
#include<algorithm>
#define N 10005
using namespace std;
int n, arr[N];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int i, j, ans=0;
cin >> n;
for(i=1; i<=n; i++) cin >> arr[i];
for(i=1; i<=n; i++){
if(arr[i]==0) continue;
if(arr[i+1]>arr[i+2]){
int x = min(arr[i+1]-arr[i+2], arr[i]);
ans += x*5;
arr[i]-=x;
arr[i+1]-=x;
x = min(arr[i], min(arr[i+1], arr[i+2]));
ans += x*7;
arr[i]-=x;
arr[i+1]-=x;
arr[i+2]-=x;
}
else{
int x = min(arr[i], min(arr[i+1], arr[i+2]));
ans += x*7;
arr[i]-=x;
arr[i+1]-=x;
arr[i+2]-=x;
x = min(arr[i], arr[i+1]);
ans += x*5;
arr[i]-=x;
arr[i+1]-=x;
}
ans += arr[i]*3;
}
cout << ans;
return 0;
}