mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 16:16:25 +00:00
E - Tahakashi and Animals
https://atcoder.jp/contests/abc251/submissions/31683208
This commit is contained in:
parent
6a7bdc6858
commit
4744b466d1
41
AtCoder/ABC251/E/E.cpp
Normal file
41
AtCoder/ABC251/E/E.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 3e5 + 5;
|
||||
|
||||
int n;
|
||||
long long a[N], f[N][2], g[N][2];
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
||||
cin >> n;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
memset(f, 0x3f, sizeof(f));
|
||||
memset(g, 0x3f, sizeof(g));
|
||||
|
||||
f[1][1] = a[1];
|
||||
for (int i = 2; i <= n; i++) {
|
||||
f[i][0] = f[i - 1][1];
|
||||
f[i][1] = std::min({f[i][1], f[i - 1][0] + a[i], f[i - 1][1] + a[i]});
|
||||
}
|
||||
|
||||
g[1][0] = a[n];
|
||||
for (int i = 2; i < n; i++) {
|
||||
g[i][0] = g[i - 1][1];
|
||||
g[i][1] = std::min({g[i][1], g[i - 1][0] + a[i], g[i - 1][1] + a[i]});
|
||||
}
|
||||
|
||||
cout << std::min({f[n][0], f[n][1], g[n - 1][0], g[n - 1][1]}) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user