Submission #146031

#TimeUsernameProblemLanguageResultExecution timeMemory
146031fedoseevtimofeyTriple Jump (JOI19_jumps)C++14
0 / 100
300 ms4976 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; bool ok(int i, int j, int k) { vector <int> r = {i, j, k}; sort(r.begin(), r.end()); i = r[0], j = r[1], k = r[2]; if (i == j || j == k) return false; return k - j >= j - i; } int solve(vector <int> a) { vector <pair <int, int>> b; int n = a.size(); for (int i = 0; i < n; ++i) b.push_back({a[i], i}); sort(b.rbegin(), b.rend()); int ans = 0; for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; ++j) { for (int k = 0; k < n; ++k) { if (ok(b[i].second, b[j].second, k)) { ans = max(ans, b[i].first + b[j].first + a[k]); } } } } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; vector <int> A(n); for (int i = 0; i < n; ++i) { cin >> A[i]; } int q; cin >> q; while (q--) { int l, r; cin >> l >> r; --l, --r; vector <int> a; for (int i = l; i <= r; ++i) a.push_back(A[i]); cout << solve(a) << '\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...