Submission #807424

#TimeUsernameProblemLanguageResultExecution timeMemory
807424oscar1fTriple Jump (JOI19_jumps)C++17
0 / 100
22 ms7212 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int MAX_VAL=500*1000+5,INFINI=1000*1000*1000; int nbVal,nbReq,debReq,finReq,rep; int val[MAX_VAL]; int maxi[MAX_VAL]; vector<int> enCours; vector<pair<int,int>> paireInter; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>nbVal; for (int i=1;i<=nbVal;i++) { cin>>val[i]; } enCours.push_back(1); for (int i=2;i<=nbVal;i++) { while (!enCours.empty() and val[enCours.back()]<=val[i]) { if (nbVal-i>=i-enCours.back()) { paireInter.push_back({enCours.back(),i}); } enCours.pop_back(); } if (!enCours.empty()) { if (nbVal-i>=i-enCours.back()) { paireInter.push_back({enCours.back(),i}); } enCours.pop_back(); } enCours.push_back(i); } cin>>nbReq; for (int ireq=1;ireq<=nbReq;ireq++) { cin>>debReq>>finReq; for (int i=finReq+1;i<=nbVal+1;i++) { maxi[i]=-INFINI; } for (int i=finReq;i>=debReq;i--) { maxi[i]=max(maxi[i+1],val[i]); } rep=0; for (auto i:paireInter) { if (i.first>=debReq) { rep=max(rep,val[i.first]+val[i.second]+maxi[2*i.second-i.first]); } } cout<<rep<<"\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...