Submission #812257

#TimeUsernameProblemLanguageResultExecution timeMemory
812257vjudge1Triple Jump (JOI19_jumps)C++17
19 / 100
529 ms241268 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 5e3 + 10; int n; ll a[N]; ll dp[N][N], mx[N][N]; int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) { for(int j = i; j <= n; j++) { mx[i][j] = max(mx[i][j - 1], a[j]); } } for(int len = 2; len <= n; len++) { for(int l = 1; l <= n - len + 1; l++) { int r = l + len - 1; dp[l][r] = max({dp[l][r - 1], dp[l + 1][r], a[l] + a[r] + mx[l + 1][(l + r) / 2]}); } } int q; cin >> q; while(q--) { int l, r; cin >> l >> r; cout << dp[l][r] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...