/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 340.0 KiB
#3 Wrong Answer 21ms 696.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) begin(v), end(v)

bool check(vector<ll> &a, vector<ll> &b)
{
    int n = a.size();
    if (n < 3)
        return true;
    for (int i = 1; i < n - 1; ++i)
        if (!((a[i] > b[i - 1] && a[i] > b[i + 1]) ||
              (b[i] > a[i - 1] && b[i] > a[i + 1])))
            return false;
    return true;
}
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 (auto &x : a)
            cin >> x;
        for (auto &x : b)
            cin >> x;

        if (n < 3)
        {
            cout << "Yes\n";
            continue;
        }
        sort(all(a));
        sort(all(b));

        bool f = false;
        for (int m = 0; m < 4 && !f; ++m)
        {
            auto ta = a;
            auto tb = b;
            if (m % 2 == 1)
                reverse(all(ta));
            if (m & 2)
                reverse(all(tb));
            f = check(ta, tb);
        }
        f ? cout << "Yes\n" : cout << "No\n";
    }
}

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:04:26
Judged At
2025-06-13 16:04:26
Judged By
Score
0
Total Time
21ms
Peak Memory
696.0 KiB