#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
//#define cin fin
//#define cout fout
using namespace std;
//ifstream fin("file.in");
//ofstream fout("file.out");
const int nmax=1e3+5;
const int mod=1e9+7;
const int mod1=998244353;
int n,a[1000005],b[1000005];
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
for(int i=0;i<n;i++) cin >> a[i];
vector <pair <int, int> > e;
stack<int>st;
for (int i = 0; i < n; i++) {
while (!st.empty() && a[st.top()] <= a[i]) {
e.push_back({st.top(), i});
st.pop();
}
if (!st.empty()) {
e.push_back({st.top(), i});
}
st.push(i);
}
int q,l,r;
cin >> q;
for(int i=1;i<=q;i++){
cin >> l >> r;
int ans=0;
for(int j=0;j<e.size();j++){
if(e[j].fr>= (l-1) && e[j].fr<=(r-1) && e[j].sc>=l && e[j].sc<=r){
for(int t=e[j].sc+1;t<=r;t++){
if((t-e[j].sc)>=(e[j].sc-e[j].fr)) ans=max(ans,a[e[j].fr]+a[e[j].sc]+a[t]);
}
}
}
cout << ans << '\n';
}
}
Compilation message
jumps.cpp: In function 'int32_t main()':
jumps.cpp:53:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<e.size();j++){
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4003 ms |
12060 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |