/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 540.0 KiB
#2 Wrong Answer 1ms 540.0 KiB

Code

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

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

    int T; 
    cin >> T;
    while (T--){
        int n;
        cin >> n;
        vector<ll> 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 (n <= 2) {
            cout << "YES\n";
            continue;
        }

        auto check = [&](const vector<ll>& X, const vector<ll>& Y) {
            priority_queue<ll> pqX(X.begin(), X.end());
            priority_queue<ll, vector<ll>, greater<ll>> pqY(Y.begin(), Y.end());

            vector<ll> x(n), y(n);

            for (int i = 1; i < n-1; i++){
                x[i] = pqX.top(); 
                pqX.pop();
            }
            x[n-1] = pqX.top(); pqX.pop();
            x[0]   = pqX.top(); pqX.pop();

            int idx = 0;
            while (!pqY.empty()){
                y[idx] = pqY.top(); 
                pqY.pop();
                idx += 2;
                if (idx >= n) idx = 1;
            }

            for (int i = 1; i < n-1; i++){
                if (!(x[i] > y[i-1] && x[i] > y[i+1]))
                    return false;
            }
            return true;
        };

        cout << (check(A,B) || check(B,A) ? "YES\n" : "NO\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 16:28:20
Judged At
2025-06-13 16:28:20
Judged By
Score
0
Total Time
1ms
Peak Memory
540.0 KiB