Skip to content

Instantly share code, notes, and snippets.

@KAIYOHUGO
Created August 21, 2021 04:07
Show Gist options
  • Save KAIYOHUGO/ce883bdf96c05298fb9cf65512c41416 to your computer and use it in GitHub Desktop.
Save KAIYOHUGO/ce883bdf96c05298fb9cf65512c41416 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC optimize("inline")
#pragma GCC optimize("omit-frame-pointer")
#pragma GCC optimize("unroll-loops")
using namespace std;
using u = long long unsigned int;
using l = long long int;
using d = long double;
enum color { red, green, blue };
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
u n;
l dp[3] = {};
cin >> n;
while (n--) {
u t;
l r, g, b;
cin >> t;
r = max(dp[color::green] - t, dp[color::blue] - t);
g = max(dp[color::red] + t, dp[color::blue] + t);
b = max(dp[color::red], dp[color::green]);
dp[color::red] = r;
dp[color::green] = g;
dp[color::blue] = b;
}
cout << *max_element(dp, dp + 3) << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment