// #pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) (int)x.size()
#define bit(a, i) ((a>>i)&1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int P = 31;
const int K = 400;
const ll inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9+7;
const int maxn = 5e3 + 10;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {1, -1, 0, 0};
int n;
int a[maxn];
int dp[2][5010][5010];
ll go(int l, int r){
cout << l << " " << r << "\n";
if(l > r) return -INF;
if(l == r) return 0;
if(l%2 && r%2){
ll sum = min(a[l+1], a[r-1]) - max(a[l], a[r]);
if(a[l+1] == a[r-1]) return go(l+1, r-1) + sum;
else if(a[l+1] < a[r-1]) return go(l+1, r) + sum;
return go(l, r-1) + sum;
}
if(!(l&1) && !(r&1)){
int mx = max(a[l+1], a[r-1]);
ll sum = min(a[l], a[r]) - mx;
return go(l+(a[l+1]==mx), r-(a[r-1]==mx)) + sum;
}
if(l&1){
int mx = max(a[l], a[r-1]);
ll sum = min(a[l+1], a[r]) - mx;
if(a[r-1] == mx)
return go(l, r-1) + sum;
}
if(r&1){
int mx = max(a[l+1], a[r]);
ll sum = min(a[l], a[r-1]) - mx;
if(a[l+1] == mx){
return go(l+1, r) + sum;
}
}
return -INF;
}
int main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
cin >> n;
for(int i=1; i<=n; i++){
cin >> a[i];
}
ll ans = go(0, n);
if(ans < 0) cout << "NO";
else cout << ans;
}
Compilation message
/usr/bin/ld: /tmp/cc5JENh8.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccssTjt9.o:password.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc5JENh8.o: in function `main':
grader.cpp:(.text.startup+0x66): undefined reference to `guess[abi:cxx11](int, int)'
collect2: error: ld returned 1 exit status