제출 #1168947

#제출 시각아이디문제언어결과실행 시간메모리
1168947mousebeaver3단 점프 (JOI19_jumps)C++20
27 / 100
22 ms5716 KiB
#define ll long long #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin>>n; vector<ll> a(n); for(ll& i : a) cin>>i; vector<ll> pre = {0}; //Greater than everything after that (index) vector<ll> dp(n, 0); //Greatest usable pair of a, b if dp[i] is c for(ll j = 1; j < n; j++) { ll p = pre.size(); for(ll i = 0; i < p; i++) { ll ind = pre[p-i-1]; ll minc = 2*(j+1) - (ind+1); if(minc > n) continue; dp[minc-1] = max(dp[minc-1], a[j]+a[ind]); if(a[ind] >= a[j]) break; } while(pre.size() && a[pre.back()] <= a[j]) pre.pop_back(); pre.push_back(j); } ll output = 0; for(ll i = 1; i < n; i++) { dp[i] = max(dp[i], dp[i-1]); output = max(output, dp[i]+a[i]); } cout<<output<<"\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...