#include <bits/stdc++.h>
using namespace std;
int a[301];
int main(){
int n; cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i];
}
int ans = 0;
for(int i = 0; i <= n - 3; i++){
int h = min(min(a[i], a[i + 1]), a[i + 2]);
a[i] -= h; a[i + 1] -= h; a[i + 2] -= h;
ans += h * 7;
}
for(int i = 0; i <= n - 2; i++){
int h = min(a[i], a[i + 1]);
a[i] -= h; a[i + 1] -= h;
ans += h * 5;
}
for(int i = 0; i <= n - 1; i++){
int h = a[i];
a[i] -= h;
ans += h * 3;
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |