Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long int
- #define pb push_back
- #define mp make_pair
- #define deb(x) cout<< #x << " " << x << "\n";
- #define MAX 9223372036854775807
- #define MIN -9223372036854775807
- #define PI 3.141592653589
- #define setbits(n) __builtin_popcountll(n)
- #define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
- const ll mod=1e9+7;
- const int N=1e5+10;
- ll dp[N][5],n;
- vector<ll> a(N);
- ll go(ll pos, ll s){
- if(pos==n){
- if(s<4) return -mod*mod;
- return 0;
- }
- if(dp[pos][s]!=-1)
- return dp[pos][s];
- ll ans;
- if(s==0)
- ans=max(go(pos+1,0),go(pos+1,1));
- else if(s==1)
- ans=max({a[pos]+go(pos+1,1),a[pos]+go(pos+1,2),a[pos]+go(pos+1,3)});
- else if(s==2)
- ans=max(go(pos+1,2),go(pos+1,3));
- else if(s==3)
- ans=max(a[pos]+go(pos+1,3),a[pos]+go(pos+1,4));
- else
- ans=go(pos+1,4);
- return dp[pos][s]=ans;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- ll T=clock();
- cin>>n;
- for(ll i=0;i<n;i++)
- cin>>a[i];
- memset(dp,-1,sizeof(dp));
- cout<<max(go(0,0),go(0,1));
- cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
- T = clock();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement