답안 #146030

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
146030 2019-08-21T16:12:17 Z fedoseevtimofey 3단 점프 (JOI19_jumps) C++14
0 / 100
149 ms 6668 KB
#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 < 3; ++i) {
        for (int j = 0; j < 3; ++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';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Incorrect 4 ms 376 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Incorrect 4 ms 376 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 145 ms 4876 KB Output is correct
2 Correct 130 ms 6636 KB Output is correct
3 Correct 126 ms 6640 KB Output is correct
4 Incorrect 149 ms 6668 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Incorrect 4 ms 376 KB Output isn't correct
6 Halted 0 ms 0 KB -