This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
typedef pair<int,pii>pi2;
void solve(){
int n;
cin >> n;
int arr[n+1];
for(int x=1;x<=n;x++){
cin >> arr[x];
}
int prefix[n+5];
int suffix[n+5];
memset(prefix,0,sizeof(prefix));
memset(suffix,0,sizeof(suffix));
for(int x=1;x<=n;x++){
prefix[x]=max(prefix[x-1]+arr[x],prefix[x]);
}
for(int x=n;x>=1;x--){
suffix[x]=max(suffix[x-1]+arr[x],suffix[x]);
}
int q;
cin >> q;
int l,r;
cin >> l >> r;
int a=1;
int b=2;
int best=0;
for(int x=1;x<=n;x++){
if(b>n) break;
best=max(best,prefix[a]+suffix[b]);
a++;
b+=2;
}
cout << best;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |