#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector <int> a(n);
for ( auto &u: a ){
cin >> u;
}
int q; cin >> q;
while ( q-- ){
int l, r; cin >> l >> r;
--l, --r;
vector <ar<int,2>> tmp;
for ( int i = l; i <= r; i++ ){
tmp.pb({-a[i], i});
}
sort(all(tmp));
vector <int> b;
for ( int i = 0; i < min(21LL, (int)tmp.size()); i++ ){
b.pb(tmp[i][1]);
}
sort(all(b));
int opt = 0;
for ( int i = 1; i + 1 < b.size(); i++ ){
for ( int j = 0; j < i; j++ ){
for ( int k = i + 1; k < b.size(); k++ ){
if ( b[i] - b[j] <= b[k] - b[i] ){
chmax(opt, a[b[i]] + a[b[j]] + a[b[k]]);
}
}
}
}
cout << opt << ln;
}
cout << '\n';
}
Compilation message
jumps.cpp: In function 'int main()':
jumps.cpp:68:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for ( int i = 1; i + 1 < b.size(); i++ ){
| ~~~~~~^~~~~~~~~~
jumps.cpp:70:40: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for ( int k = i + 1; k < b.size(); k++ ){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
6096 KB |
Output is correct |
2 |
Correct |
21 ms |
7892 KB |
Output is correct |
3 |
Correct |
22 ms |
7888 KB |
Output is correct |
4 |
Correct |
33 ms |
7916 KB |
Output is correct |
5 |
Correct |
35 ms |
7896 KB |
Output is correct |
6 |
Incorrect |
34 ms |
7120 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |