Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #pragma GCC optimize("-Ofast")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
- #pragma GCC optimize("-ffast-math")
- #pragma GCC optimize("-funroll-loops")
- #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
- #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- #define ll long long
- const long long MOD = 1e9 + 7, OO = 1e18;
- const double PI = acos(-1);
- const int N = 1e6 + 5;
- const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
- const int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
- ll dp[55], pref[55], n, a[55], mx;
- ll solve(ll idx)
- {
- if (idx == n + 1)return 0;
- ll &ret = dp[idx];
- if (~ret)return ret;
- ll c1 = pref[n] - pref[idx - 1] - solve(idx + 1);
- ll c2 = solve(idx + 1);
- return ret = max(c1, c2);
- }
- int main()
- {
- IO
- memset(dp, -1, sizeof dp);
- cin >> n;
- for (int i = 1; i <= n; i++)
- {
- cin >> a[i];
- pref[i] = a[i] + pref[i - 1];
- }
- mx = solve(1);
- cout << pref[n] - mx << ' ' << mx;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment