/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 1ms 588.0 KiB
#3 Wrong Answer 68ms 860.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 42
#endif

#define int long long

bool solve(vector<int> &a, vector<int> &b) {
    multiset<int> s, t;
    int n = a.size();
    for (int i = 0; i < n; i++) {
        s.insert(a[i]);
    }
    for (int i = 0; i < n; i++) {
        t.insert(b[i]);
    }

    vector<int> c(n, -1), d(n, -1);
    for (int i = 1; i < n - 1; i++) {
        c[i] = *s.rbegin(); s.erase(prev(s.end()));
        if (d[i - 1] == -1) {
            auto it = prev(t.upper_bound(c[i]));
            if (it == t.end()) return false;
            d[i - 1] = *it;
            t.erase(it);
        }
        if (d[i + 1] == -1) {
            if (d[i - 1] == -1) {
                auto it = prev(t.upper_bound(c[i]));
                if (it == t.end()) return false;
                d[i + 1] = *it;
                t.erase(it);
            }
        }
    }

    for (int i = 1; i < n - 1; i++) {
        if (c[i] > max(d[i - 1], d[i + 1]) || d[i] > max(c[i - 1], c[i + 1])) {
        }
        else {
            return false;
        }
    }
    return true;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        vector<int> a(n), b(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            cin >> b[i];
        }

        if (!solve(a, b) && !solve(b, a)) {
            cout << "No\n";
        }
        else {
            cout << "Yes\n";
        }
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1193 C. Roy and Peak Array
Contest
Brain Booster #10
Language
C++17 (G++ 13.2.0)
Submit At
2025-06-13 15:43:24
Judged At
2025-06-13 15:43:24
Judged By
Score
0
Total Time
68ms
Peak Memory
860.0 KiB