Created
August 21, 2021 04:07
-
-
Save KAIYOHUGO/ce883bdf96c05298fb9cf65512c41416 to your computer and use it in GitHub Desktop.
read here https://www.facebook.com/groups/1403852566495675/permalink/2976663945881188/?sfnsn=mo&ref=share
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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