/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 328.0 KiB
#3 Wrong Answer 43ms 580.0 KiB

Code


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
using vll = vector<ll>;

void done() {
    int n;
    cin >> n;
    vll a(n), b(n);
    for (ll &x : a) cin >> x;
    for (ll &x : b) cin >> x;

    if (n < 3) {
        cout << "Yes\n";
        return;
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    bool f = true;
    for (int i = 1; i < n - 1; ++i) {
        ll p_i = a[i + 1];
        ll q_i = b[i + 1];

        ll p_prev = (i == 1) ? a[0] : a[i];
        ll p_next = (i == n - 2) ? a[1] : a[i + 2];

        ll q_prev = (i == 1) ? b[0] : b[i];
        ll q_next = (i == n - 2) ? b[1] : b[i + 2];
        
        bool a_is_peak = (p_i > q_prev && p_i > q_next);
        bool b_is_peak = (q_i > p_prev && q_i > p_next);

        if (!a_is_peak && !b_is_peak) {
            f = false;
            break;
        }
    }

    cout << (f ? "Yes\n" : "No\n");
}

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

    int t;
    cin >> t;
    while (t--) {
        done();
    }
    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 17:37:37
Judged At
2025-06-13 17:37:37
Judged By
Score
0
Total Time
43ms
Peak Memory
580.0 KiB